using System; using System.Collections; using System.Collections.Generic; using Unity.Netcode; using Unity.Netcode.Transports.UTP; using UnityEngine; using UnityEngine.UI; public class LocalManager : MonoBehaviour { [SerializeField] private Button HostBtn; [SerializeField] private Button JoinBtn; [SerializeField] private Button StartButton; [SerializeField] private GameObject MainMenu; [SerializeField] private GameObject InLobbyMenu; private void Start() { if (NetworkManager.Singleton == null) return; bool isLocal = NetworkManager.Singleton.NetworkConfig.NetworkTransport is UnityTransport; if (!isLocal) Destroy(gameObject); HostBtn.onClick.AddListener(HostLobby); JoinBtn.onClick.AddListener(JoinLobby); StartButton.onClick.AddListener(StartGameServer); } private void HostLobby() { NetworkManager.Singleton.StartHost(); UpdateUI(); } private void JoinLobby() { NetworkManager.Singleton.StartClient(); NetworkManager.Singleton.OnClientConnectedCallback += _ => UpdateUI(); } private void UpdateUI() { if (!NetworkManager.Singleton.IsConnectedClient) { // Show main menu MainMenu.SetActive(true); InLobbyMenu.SetActive(false); } else { // Show In lobby ui MainMenu.SetActive(false); InLobbyMenu.SetActive(true); } } public void StartGameServer() { if (!NetworkManager.Singleton.IsHost) return; NetworkManager.Singleton.SceneManager.LoadScene("Multiplayer", UnityEngine.SceneManagement.LoadSceneMode.Single); } }