public void RpcTakeDamage(int amount) { if (!isServer || life <= 0) { return; } life -= amount; SetHealthUI(life); if (life <= 0f && !isDead) { isDead = true; life = 0; if (DeathMatchManager.RemovePlayerAndCheckWinner(this)) { Player player = DeathMatchManager.GetWinner(); player.RpcWon(); StartCoroutine(BackToLobby(5)); } RpcDied(); } }
private void Start() { if (isServer) { DeathMatchManager.AddPlayer(this); } }
int health; //Player's current health void Start() { //Set the current health health = maxHealth; //If this is the server, tell the DeathMatchManager that this tank spawned if (isServer) { DeathMatchManager.AddTank(this); } }
private void Start() { if (isServer) { DeathMatchManager.AddPlayer(this); } life = lifeBar.maxValue; lifeBarFill.color = Color.Lerp(Color.red, Color.green, life / lifeBar.maxValue); if (!isLocalPlayer) { gameObject.GetComponent <MeshRenderer>().material.color = Color.red; gameObject.tag = "Enemy"; } isDead = false; }
public void TakeDamage(float amount) { if (!isServer) { return; } m_CurrentHealth -= amount; if (m_CurrentHealth <= 0f && !m_Dead) { RpcOnDeath(); if (DeathMatchManager.RemovePlayerAndCheck(this)) { PlayerHealth player = DeathMatchManager.GetWinner(); player.RpcWon(); Invoke("BackToLobby", 3f); } } }
public void TakeDamage(int amount) { //Damage will only be calculated on the server. This prevents a hacked client from //cheating. Also, if this Tank is already dead, no need to run this code anymore. if (!isServer || health <= 0) { return; } health -= amount; //If the player is out of health... if (health <= 0) { health = 0; //...Call a method on all instances of this object on all clients (This is called an RPC) RpcDied(); //Tell the DeathmatchManager that this tank died if (DeathMatchManager.RemoveTankAndCheckWinner(this)) { TankHealth_DM tank = DeathMatchManager.GetWinner(); tank.RpcWon(); //Since the match is now over, the server will bring the players back to the lobby after //3 seconds Invoke("BackToLobby", 3f); } //Exit the method. This is usefull in case we have "hurt" effects below this. We may not want the "hurt" effects //to player when the tank has been destroyed. This leaves the method and prevents those effects from running return; } //If you have any "hurt" effects when the player takes damage, you would run them here }