using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

public class NetworkManagerUI : MonoBehaviour
{
    [Header("UI Buttons")]
    [SerializeField] private Button hostButton;
    [SerializeField] private Button clientButton;
    [SerializeField] private Button serverButton;

    private void Start()
    {
        if (hostButton != null)
            hostButton.onClick.AddListener(() => NetworkManager.Singleton.StartHost());

        if (clientButton != null)
            clientButton.onClick.AddListener(() => NetworkManager.Singleton.StartClient());

        if (serverButton != null)
            serverButton.onClick.AddListener(() => NetworkManager.Singleton.StartServer());
    }

    private void OnDestroy()
    {
        if (hostButton != null)
            hostButton.onClick.RemoveAllListeners();

        if (clientButton != null)
            clientButton.onClick.RemoveAllListeners();

        if (serverButton != null)
            serverButton.onClick.RemoveAllListeners();
    }
}
