I'm not going to write the code for you but to write a simple toggle do the following:
1. Create a boolean variable to store the on/off state
2. Change your if-statement with Input.GetButton to instead call Input.GetButtonDown, which becomes true only once on the frame the button was pressed
3. Flip the boolean variable from true/false inside the if block
4. Depending on the state of that variable setup your parameters as before
↧