Ejemplo n.º 1
0
    //碰到敌人
    private void OnCollisionEnter2D(Collision2D collision)
    {
        enemy en = collision.gameObject.GetComponent <enemy>();

        if (collision.gameObject.tag == "enemy")
        {
            if (anim.GetBool("falling") && (transform.position.y - collision.gameObject.transform.position.y >= 1f))
            {
                en.jumpOn();
                rb.velocity = new Vector2(rb.velocity.x, jumpForce * 0.8f * Time.fixedDeltaTime);
                anim.SetBool("jumping", true);
            }
            else if (transform.position.x < collision.gameObject.transform.position.x)
            {
                rb.velocity = new Vector2(-5, rb.velocity.y);
                hurtAudio.Play();
                isHurt = true;
            }
            else if (transform.position.x > collision.gameObject.transform.position.x)
            {
                rb.velocity = new Vector2(5, rb.velocity.y);
                hurtAudio.Play();
                isHurt = true;
            }
        }
    }