using UnityEngine; using Unity.Netcode; public class AutoHost : MonoBehaviour { [Header("Auto Host Settings")] [SerializeField] private bool enableAutoHost = true; [SerializeField] private bool onlyInEditor = true; private void Start() { if (ShouldAutoStart()) { if (NetworkManager.Singleton != null) { if (!NetworkManager.Singleton.IsServer && !NetworkManager.Singleton.IsClient) { NetworkManager.Singleton.StartHost(); Debug.Log("[AutoHost] Auto-host started"); } } else { Debug.LogError("[AutoHost] NetworkManager not found!"); } } } private bool ShouldAutoStart() { if (!enableAutoHost) return false; #if UNITY_EDITOR return true; #else return !onlyInEditor; #endif } }