Files
project-reset/Assets/Scripts/Units/Unit.cs

50 lines
1.2 KiB
C#

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);
}
}