Example #1
0
    public void DealDamage(int damageAmount)
    {
        //If unit has no health do nothing
        if (currentHealth == 0)
        {
            return;
        }

        //Reduce health by damage amount
        currentHealth -= damageAmount;

        //if the health drops below 0, set it to 0
        if (currentHealth < 0)
        {
            currentHealth = 0;
        }

        //If unit is not dead, stop here
        if (currentHealth != 0)
        {
            return;
        }

        //TODO
        ServerOnDie?.Invoke();
    }
Example #2
0
    public void ServerDealDamage(int damageAmount)
    {
        if (currentHealth == 0)
        {
            return;
        }

        SetHealth(Mathf.Max(currentHealth - damageAmount, 0));

        /*if(healthBar != null)
         * {
         *  HealthBar updatedBar = healthBar.GetComponent<HealthBar>();
         *  updatedBar.SetHealth(currentHealth);
         * }
         * else
         * {
         *  Debug.Log("healthBar is null");
         * }
         */
        if (currentHealth != 0)
        {
            return;
        }

        ServerOnDie?.Invoke();
    }
Example #3
0
    public void DealDamage(int damageAmount)
    {
        //If We Already Dead Return
        if (currentHealth == 0)
        {
            return;
        }

        //If The Health After You Have Taken Off The Damage, Lower Than Zero Then Stop Get Negative Number It Set to The Zero

        currentHealth = Mathf.Max(currentHealth - damageAmount, 0);

        /* It is Same As The Upper Code Segment
         *
         * currentHealth -= damageAmount;
         *
         * if(currentHealth < 0)
         * {
         *  currentHealth = 0;
         * }
         */

        if (currentHealth != 0)
        {
            return;
        }

        //If health == 0 We Died

        ServerOnDie?.Invoke();
    }
Example #4
0
    public void Die()
    {
        if (!isAlive)
        {
            return;
        }
        isAlive       = false;
        currentHealth = 0;

        ServerOnDie?.Invoke();
    }
Example #5
0
    public void Damage(float damage)
    {
        if (curHealth == 0)
        {
            return;
        }

        curHealth = Mathf.Max(curHealth - damage, 0);
        if (curHealth > 0)
        {
            return;
        }

        ServerOnDie?.Invoke();
    }
Example #6
0
 public void DealDamage(int damageAmount)
 {
     if (currentHealth == 0)
     {
         return;
     }
     // removes the damage amount from currentHealth but if it is less than 0, it returns 0
     currentHealth = Mathf.Max(currentHealth - damageAmount, 0);
     if (currentHealth != 0)
     {
         return;
     }
     ServerOnDie?.Invoke();
     Debug.Log($"we ded");
 }
Example #7
0
    public void DealDamage(int damageAmount)
    {
        if (currentHealth <= 0)
        {
            return;
        }

        currentHealth = Mathf.Max(currentHealth - damageAmount, 0);

        if (currentHealth != 0)
        {
            return;
        }

        ServerOnDie?.Invoke();
    }
Example #8
0
    public void DealDamage(int damageToDeal)
    {
        if (currentHealth == 0)
        {
            return;
        }
        currentHealth = Mathf.Max(currentHealth - damageToDeal, 0);
        Debug.Log($"Health Now: {currentHealth}");
        if (currentHealth != 0)
        {
            return;
        }
        ServerOnDie?.Invoke();

        Debug.Log("Player Died");
    }
Example #9
0
    public void DealDamage(int damageAmount)
    {
        if (_currentHealth == 0)
        {
            return;
        }

        _currentHealth = Mathf.Max(_currentHealth - damageAmount, 0);

        if (_currentHealth != 0)
        {
            return;
        }

        // dead
        Debug.Log("Dead");
        ServerOnDie?.Invoke();
    }
Example #10
0
    public void DealDamage(int damageAmount)
    {
        if (currentHealth == 0)
        {
            return;
        }

        currentHealth = Mathf.Max(currentHealth - damageAmount, 0); // make sure health can never go below 0

        if (currentHealth != 0)
        {
            return;
        }

        ServerOnDie?.Invoke();

        Debug.Log("We Died!");
    }
Example #11
0
    public void DealDamage(int damageAmount)
    {
        if (currentHealth == 0)
        {
            return;
        }                                                           // only die once!

        currentHealth = Mathf.Max(currentHealth - damageAmount, 0); // keeps it from going negative and saves a bunch of code

        if (currentHealth != 0)
        {
            return;
        }

        ServerOnDie?.Invoke(); // this raises an event that can be listened to elsewhere so each object can have a different death

        Debug.Log("We died.");
    }
Example #12
0
    public void DealDamage(int damage)
    {
        if (currentHealth == 0)
        {
            return;
        }

        currentHealth = Mathf.Max(currentHealth - damage, 0);

        if (currentHealth != 0)
        {
            return;
        }

        // TOD disabling OBJ to be targetable after its health reaches 0

        ServerOnDie?.Invoke();//event called on server when health of OBJ reaches 0
    }
Example #13
0
    public void DealDamage(int damageAmount)
    {
        if (currentHealth == 0)
        {
            return;
        }
        currentHealth = Mathf.Max(0, currentHealth - damageAmount);

        //Below here is death only.
        if (currentHealth != 0)
        {
            return;
        }

        //invoke the action above to allow all our different units and stuff to do their death handling.
        ServerOnDie?.Invoke();

        Debug.Log("We died!");
    }
Example #14
0
    public void DealDamage(int damageAmount)
    {
        if (currentHealth <= 0)
        {
            return;
        }

        currentHealth -= damageAmount;
        if (currentHealth < 0)
        {
            currentHealth = 0;
        }

        if (currentHealth == 0)
        {
            //dead
            Debug.Log(this.name + " Died");
            ServerOnDie?.Invoke();
        }
    }