using System; using System.Collections; using Reset; using Reset.Core.Tools; using UnityEngine; using Sirenix.OdinInspector; using Unity.Netcode; public class Player : NetworkBehaviour{ [HideInInspector] public PlayerControls controls; [HideInInspector] public new PlayerCamera camera; void Awake(){ GameManager.Player = gameObject; controls = GetComponent(); } void Start() { if (!NetworkManager.Singleton.IsConnectedClient && !NetworkManager.Singleton.IsHost) { Attach(); } else { StartCoroutine(WaitForOnline()); } } private IEnumerator WaitForOnline(){ while (!NetworkManager.Singleton.didAwake) { Debug.Log("waiting"); yield return null; } // Debug.Log($"{IsHost}, {IsClient}, {IsLocalPlayer}"); if (IsLocalPlayer){ GameManager.Player = gameObject; Attach(); } } public void Attach(){ if (GameManager.Player == gameObject){ GameManager.RequestNewController(); GetComponent().AttachCamera(gameObject); } } protected override void OnNetworkPostSpawn(){ // GetComponent().AttachCamera(gameObject); } // Update is called once per frame void Update() { } }