maint: moving around methods to work better with Unit/Player/Enemy classes

This commit is contained in:
Chris
2025-10-04 13:47:32 -04:00
parent 8a1d135138
commit 11f2ae26cc
4 changed files with 121 additions and 48 deletions

View File

@@ -21,53 +21,14 @@ public class Player : Unit, IKillable{
controls = GetComponent<PlayerControls>();
}
void Start(){
if (((IKillable)this).maxHealth == 0f) {
Debug.LogError($"Max health is not set for type of <b>{name}</b>. 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());
}
public override void UnitStart(){
base.UnitStart();
((IKillable)this).IKillableInitialize();
}
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<LockOnManager>().AttachCamera(gameObject);
}
}
protected override void OnNetworkPostSpawn(){
// GetComponent<LockOnManager>().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);
}
GetComponent<IKillable>().DrawHealthDebug();
}
public void TakeDamage(DamageSource[] sources){