using System; using System.Collections; using Drawing; using Reset; using Reset.Core; using Reset.Core.Tools; using Reset.Units; using UnityEngine; using Sirenix.OdinInspector; using Sirenix.Serialization; using Unity.Netcode; public class Player : Unit, IKillable{ [HideInInspector] public PlayerControls controls; float IKillable.maxHealth{ get; set; } float IKillable.currentHealth{ get; set; } void Awake(){ GameManager.Player = gameObject; controls = GetComponent(); } void Start(){ if (((IKillable)this).maxHealth == 0f) { Debug.LogError($"Max health is not set for type of {name}. Setting to 100."); ((IKillable)this).currentHealth = 10000f; } else { ((IKillable)this).currentHealth = ((IKillable)this).maxHealth; } 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(){ using (Draw.WithColor(Color.blue)) { Draw.ingame.Label2D(transform.position + Vector3.up * 2.2f, ((IKillable)this).currentHealth.ToString(), Color.blue); } } public void TakeDamage(DamageSource[] sources){ foreach (DamageSource source in sources) { TakeDamage(source); } } public void TakeDamage(DamageSource source){ ((IKillable)this).currentHealth -= source.damageDealt; if (((IKillable)this).currentHealth <= 0) { Kill(); } } public void Kill(){ throw new NotImplementedException(); } }