Why is the script running?

The script, even when enabled is set to false, will still run. I want it so if inCar is false, the functions won’t run what’s inside.

Here is the script

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

public class CarGoVrum : MonoBehaviour
{
    const string HORIZONTAL = "Horizontal";
    const string VERTICAL = "Vertical";

    float horizontalInput;
    float verticalInput;
    float currentSteerAngle;
    float currentbreakForce;
    public bool isBreaking;

    public bool inCar = false;

    public float motorForce;
    public float breakForce;
    public float maxSteerAngle;
    public float trueMaxSteerAngle;

    public WheelCollider frontLeftWheelCollider;
    public WheelCollider frontRightWheelCollider;
    public WheelCollider rearLeftWheelCollider;
    public WheelCollider rearRightWheelCollider;

    public Transform frontLeftWheelTransform;
    public Transform frontRightWheeTransform;
    public Transform rearLeftWheelTransform;
    public Transform rearRightWheelTransform;

    private void Update()
    {
        if (inCar == false)
        {
            frontRightWheelCollider.brakeTorque = 3000f;
            frontLeftWheelCollider.brakeTorque = 3000f;
            rearLeftWheelCollider.brakeTorque = 3000f;
            rearRightWheelCollider.brakeTorque = 3000f;
            maxSteerAngle = 0f;
        }
        else if (inCar == true)
        {
            maxSteerAngle = trueMaxSteerAngle;
        }
    }

    private void FixedUpdate()
    {
        if (inCar == true)
        {
            GetInput();
            HandleMotor();
            HandleSteering();
            UpdateWheels();
        }
    }


    private void GetInput()
    {
        if (inCar == false)
            return;
        horizontalInput = Input.GetAxis(HORIZONTAL);
        verticalInput = Input.GetAxis(VERTICAL);
        isBreaking = Input.GetKey(KeyCode.Space);
    }

    private void HandleMotor()
    {
        if (inCar == false)
            return;
        frontLeftWheelCollider.motorTorque = verticalInput * motorForce;
        frontRightWheelCollider.motorTorque = verticalInput * motorForce;
        currentbreakForce = isBreaking ? breakForce : 0f;
        ApplyBreaking();      
    }

    private void ApplyBreaking()
    {
        if (inCar == false)
            return;
        frontRightWheelCollider.brakeTorque = currentbreakForce;
        frontLeftWheelCollider.brakeTorque = currentbreakForce;
        rearLeftWheelCollider.brakeTorque = currentbreakForce;
        rearRightWheelCollider.brakeTorque = currentbreakForce;
    }

    private void HandleSteering()
    {
        if (inCar == false)
            return;
        currentSteerAngle = maxSteerAngle * horizontalInput;
        frontLeftWheelCollider.steerAngle = currentSteerAngle;
        frontRightWheelCollider.steerAngle = currentSteerAngle;
    }

    private void UpdateWheels()
    {
        if (inCar == false)
            return;
        UpdateSingleWheel(frontLeftWheelCollider, frontLeftWheelTransform);
        UpdateSingleWheel(frontRightWheelCollider, frontRightWheeTransform);
        UpdateSingleWheel(rearRightWheelCollider, rearRightWheelTransform);
        UpdateSingleWheel(rearLeftWheelCollider, rearLeftWheelTransform);
    }

    private void UpdateSingleWheel(WheelCollider wheelCollider, Transform wheelTransform)
    {
        Vector3 pos;
        Quaternion rot;
        wheelCollider.GetWorldPose(out pos, out rot);
        wheelTransform.rotation = rot;
        wheelTransform.position = pos;
    }

    public void setWheelColliders(bool b)
    {
        frontLeftWheelCollider.enabled = b;
        frontRightWheelCollider.enabled = b;
        rearLeftWheelCollider.enabled = b;
        rearRightWheelCollider.enabled = b;
}
}

Hello

The scrip content is irrelevant if your problem i about enable/disable a script.

Its simple: If it is runnning is because there is some object Active in hicheracy in the scene with the script attached, and the script component is also active.

I see so many errors in the script.

if (x==true)
else if (x == false)

no seed to do else if for a true/false varabile…

if (x==true)
else

Its clear theh the else meanse x is not ture.

You do one error in some places… I dont belive you dont have alerts in your script… ** warning CS0162: Unreachable code detected**

your code:

if (inCar == false)
             return;
         horizontalInput = Input.GetAxis(HORIZONTAL);
         verticalInput = Input.GetAxis(VERTICAL);
         isBreaking = Input.GetKey(KeyCode.Space);

Ther isnt any code inide the if. Your code is the same as this:

if (inCar == false)
{ nothing }
 return;

So, is doing nothing, its returning all time…

Well… read your alerts and errors first…

bye.