Push Button = Hold Button

Hey guys how can I change my script from me having to hold the button down to having to just press it once and after a certain amount of time it would ‘virtually’ release the key? This is my script.

var speed : float = 10.0;
var rotationSpeed : float = 100.0;

function Update () {
var translation : float = Input.GetAxis (“Vertical”) * speed;
var rotation : float = Input.GetAxis (“Horizontal”) * rotationSpeed;

translation *= Time.deltaTime;
rotation *= Time.deltaTime;

transform.Translate (0, 0, translation);

transform.Rotate (0, rotation, 0);

}

You could make a boolean and set this to true when the button is pressed, then, after some time set the boolean to false again. In your code, check if the boolean is true or not

Sorry im still new to scripting can you please write a script showing me how to do this?

var TurnOff : boolean = false;
var Seconds = 3.0;

function Update(){
    if (Input.GetKeyDown(Keycode.o)  (!TurnOff)){
        //The code for the action you want to do goes here

        Deactivate();       
    } 

    if(Input.GetKeyUp(Keycode.o)){
        TurnOff = false;
    }
    
}

function Deactivate(){
    //This code turns the button off after a amount of time
    WaitForSeconds(Seconds);
    TurnOff = true;
}

That should work, but I haven’t tested it in Unity.