示例#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();
        }
    }
示例#2
0
 private void Start()
 {
     if (isServer)
     {
         DeathMatchManager.AddPlayer(this);
     }
 }
示例#3
0
    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);
        }
    }
示例#4
0
    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;
    }
示例#5
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);
            }
        }
    }
示例#6
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
    }