# Block specific input for amount of time

I need to block a specific input from being able to be used for a few seconds after it is initially used.

``````#pragma strict

//create variables for the force inputs
var intYForce : int;
var intXForce : int;
var intZForce : int;
//create variable for angstyness
public var chuckingStrength : int;
//define d20fixed as a rigid body so we can do physics stuff
var d20fixed : Rigidbody;

function Start(){

//set initial value of chuckingstrength
chuckingStrength=10;

}
function Update () {

//throw the dice
if(Input.GetButtonUp("Jump")){

//set randoms for force inputs
intXForce=Random.Range(-10,10);
intYForce=Random.Range(1,10);
intZForce=Random.Range(-10,10);
//make sure they're not zero
while(intXForce==0){
intXForce=Random.Range(-10,10);
}
while(intZForce==0){
intZForce=Random.Range(-10,10);
}
d20fixed.useGravity=true;

//reset the die
}

//make it so when you press the up button angst goes up
if(Input.GetButtonDown("up")){

chuckingStrength = chuckingStrength + 1;
if(chuckingStrength==21)  {
chuckingStrength = 20;
}
}

//make it so when you press the down button angst goes down
if(Input.GetButtonDown("down")){

chuckingStrength = chuckingStrength - 1;
if(chuckingStrength==2)  {
chuckingStrength = 3;
}
}

}

//function to wait 3 seconds and reload the level
yield WaitForSeconds (3);
}
``````

Specifically, I need to make it so you can’t press jump for a few seconds while the scene reloads.

I tried messing with the dead time of the input but it doesn’t seem to be making a difference.

Obviously the yield waitforseconds isn’t interrupting the space bar (jump) from being used while it’s waiting.

I don’t know where to go from here.

Use time.deltaTime to check the amount of time that has passed by. Once it reached or passed a specific value, set a flag that “unblocks” the input.

``````float waitTime = 10.0f;
bool doneWaiting = false;
void Update()
{
// Wait until waitTime is below or equal to zero.
if(waitTime > 0) {
waitTime -= Time.deltaTime;
} else {
// Done.
doneWaiting = true;
}

// Only proceed if doneWaiting is true.
if(doneWaiting && Input.GetButton("Jump")) {
Debug.Log("Jumped!");
}
}
``````

Set a boolean like “DisableJumpInput” to true, and when pressing the jump button, check if the boolean is set to false before calling the actual jumping function.

To enable jump input again, you could just check in Update() if the boolean is set to true, and if yes, call a function that waits a few seconds and then sets teh boolean back to false.

Use a boolean that says when Jump is blocked:

``````...
//define d20fixed as a rigid body so we can do physics stuff
var d20fixed : Rigidbody;

private var blocked = false; // create this variable

function Start(){
//set initial value of chuckingstrength
chuckingStrength=10;

}
function Update () {
//throw the dice - but only if not blocked!
if(!blocked && Input.GetButtonUp("Jump")){
...
}

//function to wait 3 seconds and reload the level