Add a new PlayerSceneObject prefab with components including Camera, AudioListener, and MonoBehaviour. Create a TrooperNetwork asset to support network functionalities. These changes enhance the scene's interactivity and prepare for multiplayer features.
50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using Unity.Netcode;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class PlayerSceneObject : NetworkBehaviour
|
|
{
|
|
[Header("Look Sensitivity")]
|
|
[SerializeField] protected float _lookSensitivity = 3.0f;
|
|
|
|
[Header("Input Actions")]
|
|
[SerializeField] protected PlayerInput _playerInput;
|
|
|
|
private void Awake()
|
|
{
|
|
_playerInput = GetComponent<PlayerInput>();
|
|
}
|
|
|
|
// Network Spawn & Despawn
|
|
public override void OnNetworkSpawn()
|
|
{
|
|
base.OnNetworkSpawn();
|
|
|
|
// Enable/disable components based on ownership
|
|
gameObject.SetActive(IsOwner);
|
|
_playerInput.enabled = IsOwner;
|
|
|
|
Debug.Log($"NetworkObject ID: {NetworkObjectId} spawned with OwnerClientId: {OwnerClientId}");
|
|
}
|
|
|
|
public override void OnNetworkDespawn()
|
|
{
|
|
base.OnNetworkDespawn();
|
|
|
|
// Disable input when despawned
|
|
_playerInput.enabled = false;
|
|
|
|
Debug.Log($"NetworkObject ID: {NetworkObjectId} despawned");
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if (!IsOwner)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|