using Unity.Netcode; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.InputSystem; public class Trooper : RobotController { // Dev Debug Staff [SerializeField] Canvas screenSpaceCanvas; [Header("Gameplay Variables")] private NetworkVariable healthPoints = new NetworkVariable(); public int HealthPoints { get { return healthPoints.Value; } set { healthPoints.Value = value; } } private NetworkVariable armorPoints = new NetworkVariable(); public int ArmorPoints { get { return armorPoints.Value; } set { armorPoints.Value = value; } } private NetworkVariable ammoPoints = new NetworkVariable(); public int AmmoPoints { get { return ammoPoints.Value; } set { ammoPoints.Value = value; } } [SerializeField] private int initialHP = 100; public int InitialHP { get => initialHP; set => initialHP = value; } [SerializeField] private int initialArmor = 100; public int InitialArmor { get => initialArmor; set => initialArmor = value; } // Gameplay - Scene Awake & Start private void Awake() { characterController = GetComponent(); playerInput = GetComponent(); audioListener = GetComponentInChildren(); } // PlayerInput Events // overrided Inputs Here // Gameplay - Game Loop private void Update() { if (!IsOwner) { return; } HandleMovement(); HandleRotation(); InternalLockUpdate(); } // Networking Staff - Spawn & Despawn public override void OnNetworkSpawn() { base.OnNetworkSpawn(); playerInput.enabled = IsOwner; characterController.enabled = IsOwner; mainCam.enabled = IsOwner; audioListener.enabled = IsOwner; screenSpaceCanvas.enabled = IsOwner; // Game Variables healthPoints.Value = InitialHP; Debug.Log($"NetworkObject ID: {NetworkObjectId} spawned with OwnerClientId: {OwnerClientId}"); Debug.Log($"HP of OwnerClientID: {OwnerClientId} is {healthPoints.Value} when spawned."); } public override void OnNetworkDespawn() { base.OnNetworkDespawn(); playerInput.enabled = false; characterController.enabled = false; mainCam.enabled = false; audioListener.enabled = false; screenSpaceCanvas.enabled = false; Debug.Log($"NetworkObject ID: {NetworkObjectId} despawned"); } // Networking Staff - Gameplay [ServerRpc] private new void JumpServerRPC() { if (characterController.isGrounded) { Debug.Log("Jumping as Trooper triggered."); } } [ServerRpc] private new void ShootServerRPC() { weapon.Shooting(); } [ServerRpc] private new void AimServerRPC() { Debug.Log("Aim as Trooper triggered."); } [ServerRpc] private new void CrouchServerRPC() { Debug.Log("Crouch as Trooper triggered."); } [ServerRpc] private new void InteractServerRPC() { Debug.Log("Interact as Trooper triggered."); } }