Files
project-reset/Assets/Scripts/Player/Player.cs
2025-09-03 19:37:27 -04:00

59 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()
{
}
}