예제 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        ballController ctrl = collision.gameObject.GetComponent <ballController>();

        if (ctrl != null)
        {
            ctrl.isAttracted = true;
            pad_ctrl.addBallToLaunchList(collision.gameObject);
            //关闭尾迹渲染
            ctrl.gameObject.GetComponent <TrailRenderer>().enabled = false;
            //清除力
            ctrl.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector3(0, 0, 0);
        }
    }
예제 #2
0
    //用于刷新新球的静态方法
    public static void newBall()
    {
        Vector3 position;

        if (_pad != null)
        {
            //获取位置并做偏移
            position    = pad.transform.position;
            position.y += ballInitOffset;
        }
        else
        {
            //抓取不到pad,使用默认位置
            position = new Vector3(0, -4.15f, 0);
        }

        //刷新球
        //初始球不刷新特效
        if (isLevelStarted)
        {
            Instantiate(particle_ray_launcher, position, new Quaternion(0, 0, 0, 0));
        }
        //刷新新球
        GameObject ball_new = Instantiate(_ball, position, new Quaternion(0, 0, 0, 0));

        currentBall = ball_new;
        //把球加入到球列表
        ballList.Add(ball_new);
        //加入待发射列表
        if (pad_ctrl == null)
        {
            findPad();
        }
        pad_ctrl.addBallToLaunchList(ball_new);
        ballController ctrl = ball_new.GetComponent <ballController>();

        //让球附在板子上
        ctrl.isAttracted = true;
    }