Make this script toggle?

I have a code that changes a variable called yOffset in my camera from 0 to 0.2 when the input switch shoulders is held. Here’s the script…

var NormalY: float = 0; // yOffset while not aiming
var AimY: float = 0.2; // yOffset while aiming
private var cameraScript: MouseOrbitOTS;
function Start(){
     cameraScript = GetComponent(MouseOrbitOTS);
     var ch:Camera = GetComponent(Camera);
}
function Update(){
     var cameraY = NormalY;
     if (Input.GetButton("Aim")){
         cameraY = AimY;
      }
      cameraScript.yOffset = cameraY; // set yOffset while aiming or not aiming
}

But, I want this script to be toggled and not only work when the input i held. What would I do?

Switch to GetButtonUp. Use a bool to track the current state. Pseudo code as follows.

bool isOn;

void Toggle () {
    isOn = !isOn;
    if (isOn){
        // Do stuff
    } else {
        // Do other stuff
    }
}