feat: basic online working with relay
This commit is contained in:
@@ -1,26 +1,55 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Reset;
|
||||
using Reset.Core.Tools;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
using Unity.Netcode;
|
||||
|
||||
|
||||
public class Player : MonoBehaviour{
|
||||
public class Player : NetworkBehaviour{
|
||||
[HideInInspector] public PlayerControls controls;
|
||||
[HideInInspector] public new PlayerCamera camera;
|
||||
|
||||
void Awake(){
|
||||
GameManager.Player = gameObject;
|
||||
controls = GetComponent<PlayerControls>();
|
||||
GameManager.RequestNewController();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
Debug.Log(GameManager.Player);
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user