首页 > 解决方案 > 为什么球在越过边缘时(即比赛结束)没有下降?

问题描述

这里的程序没有使用以下行更新:rb.velocity = new Vector3 (0, -25f, 0); 球在通过边缘时应该会掉下来,但它会卡在边缘..我还在边缘和球之间产生零摩擦..

void Start () {
    started = false;
    gameOver = false;
}

void Update () {

    if (!started) {
        if (Input.GetMouseButtonDown (0)) {
            rb.velocity = new Vector3 (speed, 0, 0);
            started = true;
        }
    }

    Debug.DrawRay (transform.position, Vector3.down, Color.red);

    if (!Physics.Raycast (transform.position, Vector3.down, 1f)) {
        gameOver = true;
        rb.velocity = new Vector3 (0, -25f, 0);
    }

    if (Input.GetMouseButtonDown (0) && !gameOver)
    {
        SwitchDirection ();
    }
}
void SwitchDirection(){
    if (rb.velocity.z > 0)
    {
        rb.velocity = new Vector3 (speed, 0, 0);
    }
    else if (rb.velocity.x > 0){
        rb.velocity = new Vector3 (0, 0, speed);
    }

}

标签: c#unity3d

解决方案


推荐阅读