using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CannonBallPoolManager : MonoBehaviour
{
    public CannonBallController[] cannonBalls;
    public Vector2[] offscreenPositions;

    public static CannonBallPoolManager Instance;

    private int poolIndex;


    void Awake()
    {
        Instance = this;
    }

    public CannonBallController GetCannonBall()
    {
        var cannonBall = cannonBalls[poolIndex];
        cannonBall.spawnTime = Time.time;
        cannonBall.gameObject.SetActive(true);
        poolIndex = (poolIndex + 1) % cannonBalls.Length;
        return cannonBall;
    }

    public void ResetCannonBall(CannonBallController cannonBall)
    {
        cannonBall.body.velocity = Vector2.zero;
        cannonBall.body.angularVelocity = 0f;
        cannonBall.transform.rotation = Quaternion.identity;
        cannonBall.transform.position = cannonBall.poolOffscreenPosition;
        cannonBall.gameObject.SetActive(false);
    }
}
