using UnityEngine;

public class PlayerManager : MonoBehaviour
{
    public static PlayerManager Instance { get; private set; }

    [SerializeField] private GameObject playerPrefab;
    private GameObject playerInstance;

    public GameObject Player => playerInstance;

    private void Awake()
    {
        Instance = this;
    }

    private void Start()
    {
        if (playerInstance == null && playerPrefab != null)
        {
            playerInstance = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity, transform);
        }
        else if (playerInstance == null)
        {
            Debug.LogError("Player Prefab이 할당되지 않았습니다!");
        }
    }

    // Player 스크립트 참조 쉽게 하는 편의 메서드
    public T GetPlayerComponent<T>() where T : Component
    {
        if (playerInstance == null)
        {
            Debug.LogWarning("플레이어 인스턴스가 존재하지 않습니다.");
            return null;
        }
        return playerInstance.GetComponent<T>();
    }
}
