using UnityEngine;

public class PlayerSpawner : MonoBehaviour
{
    public GameObject player;
    public GameObject gameManager;

    // Start is called before the first frame update
    void Start()
    {
        gameObject.GetComponent<SpriteRenderer>().enabled = false;
        if (gameManager == null) gameManager = GameObject.FindGameObjectsWithTag("GameManager")[0];
    }

    // Update is called once per frame
    void Update()
    {
        if (gameManager == null) gameManager = GameObject.FindGameObjectsWithTag("GameManager")[0];
        else
        {
            if (gameManager.GetComponent<Game_Manager>().readPlayerSpawnEnabled())
            {
                Instantiate(player, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                gameManager.GetComponent<Game_Manager>().notifyPlayerSpawn();
            }
        }
    }
}
