Ejemplo n.º 1
0
    public void TakeDamage(float damage)
    {
        healthSlider.SubtractHealth(damage);

        StartCoroutine(setUnderAttack());

        healthText.text = ((int)healthSlider.Health).ToString();

        var position = transform.position;

        position.Set(position.x, position.y + HEIGHT_OFFSET, position.z);
        var text_holder = Instantiate(dmgTakenText, position, Quaternion.Euler(Camera.main.transform.eulerAngles));

        text_holder.transform.GetChild(0).GetComponent <TextMeshPro>().SetText("- " + damage);

        if (healthSlider.Health <= 0)
        {
            if (Faction == FactionEnum.Player)
            {
                menuScript.GameOver();
            }
            else
            {
                menuScript.GameWin();
            }
        }
    }
Ejemplo n.º 2
0
    public virtual void TakeDamage(float damage)
    {
        if (_isDead)
        {
            return;
        }

        unitHealth.SubtractHealth(damage);

        if (unitHealth.Health <= 0)
        {
            _isDead = true;

            EventManager.Instance.ExecuteEvent <IUnitDead>((x, y) => x.OnUnitDead(this));

            animator.Play(deathAnimationClip.name);

            if (_areSoundsEffectsOn)
            {
                audioSource.clip = deathClips[UnityEngine.Random.Range(0, deathClips.Count)];
                audioSource.Play();
            }

            //disable colliders
            var colliders = GetComponentsInChildren <Collider>();
            foreach (Collider collider in colliders)
            {
                collider.enabled = false;
            }

            Destroy(gameObject, deathAnimationClip.length + 1f);
        }
        var position = transform.position;

        position.Set(position.x, position.y + HEIGHT_OFFSET, position.z);
        var text_holder = Instantiate(dmgTakenText, position, Quaternion.identity);

        text_holder.transform.GetChild(0).GetComponent <TextMeshPro>().SetText("- " + damage);
    }