hello there , I would like to know how on earth ia one supposed to temporarily disable a keyboard key , namely the up down , left and right arrow keys only.
how would i store the disabling function as a boolean? where by i can easily toggle between its true and false function if a action is dine
for example
// disable arrow keys on awake here with boolean name of disabling function" = true;
if (Input.GetKeyDown(“y”)){
// enable arrow keys here with “boolean name of disabling function” = false;
/how do i enable the arrow keys here for about ummm 5 seconds when the arrow key is pressed , the keys will be disabled 5 seconds after pressed/
}
“boolean name of disabling function” = true; //after 5 seconds
it would be great if you could help me with this problem
i will just use waitForSeconds for the timer part -_____________- lol
var arrowsEnabled = true;
function Update()
{
if (Input.GetKeyDown("y"))
{
arrowsEnabled = false;
yield WaitForSeconds(5);
arrowsEnabled = true;
}
if (arrowsEnabled)
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
... do something with arrow keys ...
}
}
Separate your inputs, and only allow them when you choose :
private var isKeysEnabled : boolean = false;
function Update()
{
if ( Input.GetKeyDown(KeyCode.Y) )
{
if (isKeysEnabled)
{
isKeysEnabled = false;
}
else
{
isKeysEnabled = true;
}
}
if (isKeysEnabled)
{
// do your arrow keys input stuff here
// this only works when isKeysEnabled = true;
}
}
Something like this might work. You have a variable that controls whether you check for the cursor keys. In the example you can set this variable to true or false using t or f. In your code you’ll want to change the value of keysDisabled based on your timer. Note that this code has never been compiled, so it might contain typos.
// untested pirate code, ahoy me hearties
var keysDisabled : boolean = false;
// blah blah
if (keysDisabled == false) {
if (Input.GetKeyDown("y")) {
// etc
}
}
if (Input.GetKeyDown("t")) {
keysDisabled = true;
}
if (Input.GetKeyDown("f")) {
keysDisabled = false;
}