Пример #1
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        frog frog = other.gameObject.GetComponent <frog>();
        Slug slug = other.gameObject.GetComponent <Slug>();

        if (other.gameObject.tag == "Enemy")
        {
            if (isFalling)
            {
                if (other.gameObject.name == "frog-idle")
                {
                    frog.Tremble();
                    m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
                }
                if (other.gameObject.name == "slug")
                {
                    slug.Tremble();
                    m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
                }
            }
            else
            {
                isHurting = true;
                handleHealth();

                if (other.gameObject.transform.position.x > transform.position.x)
                {
                    //enemy is to my right therefore i should be damaged and move left
                    m_Rigidbody2D.velocity = new Vector2(-hurtForce, m_Rigidbody2D.velocity.y);
                }
                else
                {
                    //enemy is to my left therefore i should be damaged and move right
                    m_Rigidbody2D.velocity = new Vector2(hurtForce, m_Rigidbody2D.velocity.y);
                }
            }
        }
        else if (other.gameObject.tag == "Eagle")
        {
            handleHealth();
        }
        else if (other.gameObject.name == "Depth")
        {
            handleHealth();
            transform.localPosition = new Vector3(-14.01f, 2.49f, 0f);
        }
    }