Ejemplo n.º 1
0
    /// <summary>
    /// Has to take into account the armor of the target unit, immune state etc...
    /// </summary>
    /// <param name="amount"></param>
    public void TakeDamage(int amount)
    {
        int totalDamage = (amount - unitData.stats.Def).ZeroCheck();

        unitData.stats.Hp -= totalDamage;
        //unitData.stats.Hp = Mathf.Clamp(unitData.stats.Hp, 0, unitData.stats.maxStat);

        DamagePopup popup = DamagePopup.Create(totalDamage, GridManager.GetTileToCellFromWorld(positionGrid));

        popup.Animate();
        Destroy(popup.gameObject, GV.moveAnimationTime);

        if (unitData.stats.Hp <= 0)
        {
            UnitManager.Instance.unitDictionnary.Remove(positionGrid);
            StartCoroutine(Die());
        }
    }