Problem HandBrake with Key again

Hello, Problem HandBrake with Key again, I can press handbrake is brake next again press Handbrake can’t unbrake with key again.

    var rearWheel1 : WheelCollider;
    var rearWheel2 : WheelCollider;
    var brakemaks = 10;
    var brakemaks2 = 0;
    
    private var brakeks = 10;
    private var brakeks2 = 0;
    
    function Update() {
      if (Input.GetKeyDown("b")) {
        rearWheel1.brakeTorque = brakemaks * brakeks;
        rearWheel2.brakeTorque = brakemaks * brakeks;
        }
    	else
    	{
      if (Input.GetKeyDown("b")) {
        rearWheel1.brakeTorque = brakemaks2 * brakeks2;
        rearWheel2.brakeTorque = brakemaks2 * brakeks2;
        }
    }
    }

Sorry my bad speak english

Let’s remove all the extra code and take a look.

if (Input.GetKeyDown("b"))
{
}
else if (Input.GetKeyDown("b"))
{
}

This code is saying “If the b key is presed then do something, otherwise if the b key is pressed do something else”. Well, if the b key is pressed, it will always do the first thing and never the second.

What you’re trying to do here is toggle the state between two values. A way to handle this is with a boolean variable.

var brakeOn : bool = false;


function Update()
{
  // is the b key pressed?
  if (Input.GetKeyDown("b"))
  {
    // if the brake is already on then we want to turn it
    // off, and change the boolean so we know it's off, 
    // otherwise if it's off then we want to turn it on
    // and set the variable so we know it's on
    if (brakeOn)
    {
      // turn brake off
      rearWheel1.brakeTorque = 0;
      rearWheel2.brakeTorque = 0;
      brakeOn = false;
    }
    else
    {
      // turn brake on
      rearWheel1.brakeTorque = brake_maks * brakeks;
      rearWheel2.brakeTorque = brake_maks * brakeks;
      brakeOn = true;
    }
  }
}