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

@@ -1,4 +1,50 @@
using Unity.Netcode;
using System.Collections;
using Reset;
using Unity.Netcode;
using UnityEngine;
public class Unit : NetworkBehaviour{
public virtual void Start(){
UnitStart();
}
public virtual void UnitStart(){
OnlineStart();
}
protected void OnlineStart(){
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<LockOnManager>().AttachCamera(gameObject);
}
}
void Update(){
}
protected override void OnNetworkPostSpawn(){
// GetComponent<LockOnManager>().AttachCamera(gameObject);
}
}