Help with a movement script!

Hi, I have a problem. The ball is on a path and to keep continue rolling it have to pass through the obstacle, the only way to do that is changing the color which has to be ste same of the obstacle. if the color is different the ball don’t pass, so is game over. The problem is that the game over part doesn’t work, any idea?

Thank you :slight_smile:

using UnityEngine;

public class Movement : MonoBehaviour
{
    [SerializeField]

    public Rigidbody rb;
    private float forwardForce=300f;
    public bool partito;
    public bool gameOver;

    public static Movement current;

     void Awake()
    {
            current = this;
    }
    private void Start()
    {
         partito = false;
         gameOver = false;
}
    void FixedUpdate()
    {

        if (Input.GetMouseButtonDown(0) && !partito)
        {
            rb.velocity = new Vector3(0, 0, forwardForce * Time.deltaTime);
            partito = true;
  
        }

        if (partito && !gameOver)
        {
            rb.velocity = new Vector3(0, 0, forwardForce * Time.deltaTime);
            UIManager.current.GameStart();

        }
        if ( rb.velocity== Vector3.zero && partito)
        {

            Spawner.current.gameOver = true;
            UIManager.current.GameOver();
        }
    }

}

What about it does not work? Does the gameOver variable not become true? Does the if statement handling the gameover not get entered? Something else that’s wrong? You need to be a bit more specific.

Also, probably unrelated to the problem, but you are not supposed to do anything non physics related in FixedUpdate. So at the very least, this means you should rather check for inputs in Update() and remember them for use in FixedUpdate(). The same probably applies to UI related lines.