Esempio n. 1
0
    private void OnTriggerStay(Collider other)
    {
        if (liver == null || liver.IsInvincible)
        {
            return;
        }

        if (other.CompareTag("HurtEnvironment") || other.CompareTag("HurtPlayer"))
        {
            scene.fight = true;

            Player player = other.GetComponentInParent <Player>();
            if (player != null)
            {
                player.LandedHit(gameObject);
            }
            else
            {
                IHurter hurter = other.GetComponent <IHurter>();
                if (hurter != null)
                {
                    hurter.LandedHit(gameObject);
                }
            }

            animator.SetInteger("State", 2);

            liver.TakeDamage(1);
            Instantiate(Prefabs.Get("HitEffect"), transform.transform.position, Quaternion.identity);
            Vector3 direction = other.transform.position - transform.position;
            direction.Normalize();
        }
    }
Esempio n. 2
0
    private void OnTriggerStay(Collider other)
    {
        if (liver == null || liver.IsInvincible)
        {
            return;
        }

        if (other.CompareTag("HurtEnvironment") || other.CompareTag("HurtPlayer"))
        {
            Player player = other.GetComponentInParent <Player>();
            if (player != null)
            {
                player.LandedHit(gameObject);
            }
            else
            {
                IHurter hurter = other.GetComponent <IHurter>();
                if (hurter != null)
                {
                    hurter.LandedHit(gameObject);
                }
            }

            ChangeState(FlyingHeadState.Hurt);

            liver.TakeDamage(1);
            Instantiate(Prefabs.Get("HitEffect"), transform.transform.position, Quaternion.identity);
            Vector3 direction = other.transform.position - transform.position;
            direction.y = 0;
            direction.Normalize();
            rigidbody.AddForce(-direction * 450);

            if (healthUi != null)
            {
                healthUi.SetActive(true);
                if (healthUiTimer != null)
                {
                    Destroy(healthUiTimer.gameObject);
                }
                healthUiTimer = Timer.Create(1f, () =>
                {
                    if (healthUi != null)
                    {
                        healthUi.SetActive(false);
                    }
                });
            }
        }
    }
Esempio n. 3
0
    public void TakeDamage(int damage = 1, GameObject other = null)
    {
        if (IsInvincible)
        {
            return;
        }
        Health           -= damage;
        IsInvincible      = true;
        invincibilityTime = InvincibilityDuration;
        Sounds.Play("Hit");

        if (other)
        {
            IHurter hurter = other.GetComponent <IHurter>();

            if (hurter != null)
            {
                hurter.LandedHit(gameObject);
            }
        }
    }