Why is my boolean always true?

I’m trying to stop input when the player has crashed.

why is my boolean always true in update?

heres my script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CarInputHandler : MonoBehaviour
{
   
    //Components
    TopDownCarController topDownCarController;
    public StartLight startLight;

    public bool canDrive = false;

    //Awake is called when the script instance is being loaded.
    void Awake()
    {
        topDownCarController = GetComponent<TopDownCarController>();
       
    }

    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame and is frame dependent
    void Update()
    {
        print(canDrive);
        if (startLight.raceStarted && canDrive)
        {
            Vector2 inputVector = Vector2.zero;

            //Get input from Unity's input system.
            inputVector.x = SimpleInput.GetAxis("Horizontal");
            inputVector.y = SimpleInput.GetAxis("Vertical");

            //Send the input to the car controller.
            topDownCarController.SetInputVector(inputVector);
        }
    }
}

Did you set it to true in the inspector?

The value assigned in the inspector will override the default value you give it in the script. If you don’t need the value to be serialised, add a NonSerialized attribute to it

[NonSerialized]
public bool canDrive = false;

changing this line from true to false does nothing, the player can still drive
public bool canDrive = false;

lol, yes, havent had that happen for months now!!! Thanks!!!

1 Like