//碰撞检测
    public virtual void OnCollisionEnter2D(Collision2D collision)
    {
        ballController ball = collision.gameObject.GetComponent <ballController>();

        //检测碰撞的物体是否为ball
        if (ball != null)
        {
            ballHit(collision.gameObject.transform.position);
        }
        else
        {
            Prop_shoot_bullet bullet = collision.gameObject.GetComponent <Prop_shoot_bullet>();
            if (bullet != null)
            {
                ballHit(collision.gameObject.transform.position);
                Destroy(collision.gameObject);
            }
        }
    }
Exemple #2
0
    //Trigger
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ballController ball_ctrl = collision.gameObject.GetComponent <ballController>();

        //检测碰撞的物体是否为ball
        if (ball_ctrl != null)
        {
            if (ball_ctrl.isPowerful || collision_type == 2)
            {
                ball = collision.gameObject;
                if (!ball_ctrl.isPowerful)
                {
                    //如果球打到了砖块则不认为球卡住
                    ball_ctrl.updateRecordPosition();
                    ballHit_trigger();
                }
                else
                {
                    //如果球打到了砖块则不认为球卡住
                    ball_ctrl.updateRecordPosition();
                    //Powerful状态下直接摧毁砖块
                    destroyBrick();
                }
            }
        }
        else
        {
            Prop_shoot_bullet bullet_ctrl = collision.gameObject.GetComponent <Prop_shoot_bullet>();
            if (bullet_ctrl != null && collision_type == 2)
            {
                ball = collision.gameObject;
                ballHit_trigger();
                Destroy(collision.gameObject);
            }
        }
    }