using UnityEngine;
using UnityEngine.InputSystem;

public class CameraMovement : MonoBehaviour
{
    public float speed = 1f;

    void Start()
    {
        this.gameObject.transform.position = new Vector3(0, 0, -10);
    }

    void Update()
    {
        if (Keyboard.current.downArrowKey.isPressed)
        {
            if (GameManager.instance.GetActivePlayerSwitching()) return;
            GameManager.instance.SetActivePlayerSwitching(true);

            GameManager.instance.GetActivePlayer().OnDeactivate();

            if (GameManager.instance.GetActivePlayerId() == "Snail") GameManager.instance.SetActivePlayerId("Ghost");
            else GameManager.instance.SetActivePlayerId("Snail");

            GameManager.instance.GetActivePlayer().OnActivate();
            this.MoveToPosition(new Vector3(GameManager.instance.GetPlayerPosition().x, GameManager.instance.GetPlayerPosition().y, -10));

            foreach (BoxController box in GameManager.instance.GetBotControllers())
            {
                box.PutDownBox();
            }
        } else
        {
            GameManager.instance.SetActivePlayerSwitching(false);
        }

        this.MoveToPosition(new Vector3(GameManager.instance.GetPlayerPosition().x, GameManager.instance.GetPlayerPosition().y, -10));
    }

    void MoveToPosition(Vector3 position)
    {
        this.gameObject.transform.position = position;
    }
}
