Beispiel #1
0
    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();
        }
    }
Beispiel #2
0
    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);
            }
        }
    }
Beispiel #3
0
    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
    }