Ejemplo n.º 1
0
    protected void TakeDamage(float _dame)
    {
        transform.GetChild(0).GetComponent <SpriteRenderer>().color = new Color32(128, 42, 42, 128);
        parHit.Play();
        int numberRemove = (int)(_dame / infoHero.health);
        int numberSub    = numberRemove;

        if (numberSub > infoHero.countHero)
        {
            numberSub = infoHero.countHero;
        }
        if (infoHero.countHero <= 0)
        {
            numberSub = 0;
        }
        infoHero.countHero -= numberRemove;

        if (house != null)
        {
            house.AddHero(-numberSub);
        }
        else if (goldMine != null)
        {
            goldMine.AddHero(idGoldMine, -numberSub);
            if (GameManager.Instance.isAttackGoldMineEnemy && infoHero.ID < 31)
            {
                long expAdd = (long)((numberSub * GameManager.Instance.ratioBorn * GameManager.Instance.ratioBorn) / (GameManager.Instance.dateGame));
                GameManager.Instance.AddExp(expAdd);
            }
        }

        if (infoHero.countHero <= 0)
        {
            infoHero.countHero = 0;
            Die();
        }
        else
        {
            Invoke("EndTakeDamage", 0.15f);
        }
        txtCountHero.text = UIManager.Instance.ConvertNumber(infoHero.countHero);
    }