using Mirror;
using UnityEngine;
using UnityEngine.InputSystem;

public class RtsNetworkManager : NetworkManager
{
    [SerializeField] private GameObject _unitSpawnerPrefab;

    public override void OnServerAddPlayer(NetworkConnectionToClient conn)
    {
        base.OnServerAddPlayer(conn);

        NetworkPlayer player = conn.identity.GetComponent<NetworkPlayer>();
        player.SetDisplayName($"Player {numPlayers.ToString()}");
        player.SetPlayerColor(ColorManipulation.GetRandomColor());

        Transform playerStartPosition = conn.identity.transform;

        GameObject unitSpawner = Instantiate(
            _unitSpawnerPrefab,
            playerStartPosition.position,
            playerStartPosition.rotation);

        NetworkServer.Spawn(unitSpawner, conn);
    }
}