58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
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<PlayerControls>();
|
|
}
|
|
|
|
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<LockOnManager>().AttachCamera(gameObject);
|
|
}
|
|
}
|
|
|
|
protected override void OnNetworkPostSpawn(){
|
|
// GetComponent<LockOnManager>().AttachCamera(gameObject);
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|