Здесь пробграмма не обновляется со строкой: 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);
}
}