void Start() { // First, if there are multiple canvas' within the player object... // then we must find the one with the "HUD" tag List <int> arrayIndexes = new List <int>(); var canvasComponents = GetComponentsInChildren <Canvas>(); for (int i = 0; i < canvasComponents.Length; i++) { if (canvasComponents[i].CompareTag("HUD")) { // Remember the array index so that we can directly modify // the canvas that has the "HUD" tag arrayIndexes.Add(i); //hudCanvas = canvasComponents[i]; } } foreach (int arrayIndex in arrayIndexes) { // By default, disable the HUD Canvas if the developer forgets to disable in the Unity editor GetComponentsInChildren <Canvas>()[arrayIndex].enabled = false; if (isLocalPlayer) { DevLog.Log("LocalCanvas", "Enable UI for LocalPlayer netId: " + GetComponent <NetworkIdentity>().netId); // Enable the HUD UI canvas for our local player instance. This will ensure // that other player UIs will never overlap with the host or other clients... GetComponentsInChildren <Canvas>()[arrayIndex].enabled = true; } } }
public void DealDamageToEnemy(GameObject otherObject) { GameObject player = NetworkServer.FindLocalObject(ownerId); damageRate = player.GetComponent <PlayerStats>().Damage; DevLog.Log("Bullet", "Player with id <" + ownerId.ToString() + "> dealt damage to enemy with " + damageRate); otherObject.GetComponent <Health>().EnemyTakeDamage(damageRate, ownerId); }
/// <summary> /// Methods occurs when player's health reaches/is zero. /// </summary> void OnPlayerHealthZero() { DevLog.Log("Health", "The player health is zero... Changing color... syncing"); // Change the color of the player to reflect their "dead" state GetComponentInChildren <MeshRenderer>().material.color = Color.red; // By setting the "isAlive" bool to false, we trigger // the SyncVar hook in the CharacterState thePlayer.status = CharacterStatus.RESCUE; }
public void TakeDamage(float amount) { if (!isServer) { return; } currentHealth -= amount; if (currentHealth <= 0.0f) { currentHealth = 0.0f; RpcOnPlayerDead(); DevLog.Log("Health", "Player id <" + GetComponent <NetworkIdentity>().netId + "> is dead..."); } }
void OnTriggerExit(Collider other) { if (other.CompareTag("Player")) { // If the PLAYER i encounter is in a "RESCUE" state, therefore // it means that i can attempt to revive the other person... if (playerToRescue != null && playerToRescue.characterState.status == CharacterStatus.RESCUE) { // DEBUG targetId = other.GetComponent <NetworkIdentity>().netId; // When PLAYER1 (myself) enters the revive zone, we want to show the revive ui box rescueButton.gameObject.SetActive(false); DevLog.Log("ReviveTrigger", "Player id <" + myNetId + "> exited vicinity of <" + targetId.Value + ">"); } } }
void CmdRescueButtonOnClick() { if (playerToRescue != null) { //DevLog.Log("ReviveTrigger", "Player id <" + myNetId + "> attempting to revive <" + this.playerToRescue.tmpNetworkId + ">"); try { // Tell the server to RESCUE the downed player by restoring their health and their character appearance playerToRescue.CmdOnPlayerRescue(); } catch (Exception ex) { string error = ex.Message; DevLog.Log("ReviveTrigger", "Exception thrown. Ignoring because player is already revived.\n" + error); } RpcSetRevivePanelActive(false); } }
void OnDisable() { DevLog.Log("ReviveTrigger", "OnDisable executing"); rescueButton.onClick.RemoveListener(delegate { CmdRescueButtonOnClick(); }); }
public override void OnServerConnect(NetworkConnection conn) { DevLog.Log("NetworkManagerCustom", "Someone connected to the server: " + conn.connectionId); }
void OnChangeStatus(CharacterStatus status) { DevLog.Log("CharacterState", "Player id <" + GetComponent <NetworkIdentity>().netId + "> status = " + status.ToString()); this.status = status; }