Esempio n. 1
0
    public void TakeDamage(int damage, Vector2 knockback)
    {
        if (!invincible)
        {
            hp -= damage;

            if (hp > 0)
            {
                StartCoroutine(takeDamageAnimation());
                knockback *= 5;
                rb.AddForce(knockback, ForceMode2D.Impulse);
            }
            else
            {
                //  Die
                isDead = true;
                enemyAI.CancelInvoke();
                knockback *= 20;
                rb.AddForce(knockback, ForceMode2D.Impulse);

                if (enemyDirection == "Right")
                {
                    transform.rotation = Quaternion.Euler(Vector3.forward * 90);
                }
                else
                {
                    transform.rotation = Quaternion.Euler(Vector3.back * 90);
                }


                sprite.color     = new Color(0.25f, 0.25f, 0.25f, 1);
                gameObject.layer = LayerMask.NameToLayer("Dead Enemy");
            }
        }
    }
Esempio n. 2
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.tag == "Player")
     {
         parent.CancelInvoke();
         //parent.InvokeRepeating("UpdatePath", 0f, 0f);
     }
 }