Example #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //somente o filho "Ghost" consegue entrar em contato com "Enemy"s
        if (collision.transform.CompareTag("Enemy"))
        {
            IStompable enemy = collision.transform.GetComponent <IStompable>();
            if (enemy != null)
            {
                if ((transform.position - collision.transform.position).y > enemy.GetYStompRange())
                {
                    enemy.OnStompEvent(this);
                }
                else
                {
                    enemy.OnTouchEvent(this);
                }
            }
        }
        else if (collision.CompareTag("Zipline"))
        {
            Zipline zipline = collision.GetComponent <Zipline>();
            if (zipline && !zipline.Disabled)
            {
                Vector3 snap = zipline.SnapedPosition(transform.position);
                snap -= transform.position;
                if (snap.magnitude < 1f)
                {
                    transform.position += snap;
                    SetZippingState(zipline);
                }
            }
        }
        else if (collision.transform.CompareTag("Hitbox") || collision.transform.CompareTag("Explosion"))
        {
            Hitbox hitbox = collision.GetComponent <Hitbox>();
            if (hitbox && hitbox.id != ID.Player)
            {
                SetDamage(collision.transform.position, hitbox.damage);
            }
        }
        else if (collision.CompareTag("Blastzone"))
        {
            controller.Die();
        }
        else if (collision.CompareTag("Exit"))
        {
            Window windowScript = collision.GetComponent <Window>();
            if (windowScript)
            {
                groundMovement.enabled = airborneMovement.enabled = zippingMovement.enabled = false;
                GetComponent <Collider2D>().enabled = false;

                m_animator.SetBool("Airborne", true);
                m_animator.SetFloat("HorizontalSpeed", 0f);
                m_animator.SetTrigger("Reset");

                controller.TravelThroughExit(collision.transform.position, windowScript);
            }
        }
    }