boolean is supposed to stop the player from being able to input the keycode “moveUp” or “moveDown” for 1 second because i said its “false” then wait for one second but it still continues being true and there isnt a one second delay once the reset players function is called. This is in java script can anyone help me fix it?
var playersAreReady : boolean = true;
var moveUp : KeyCode;
var moveDown : KeyCode;
var speed : float = 15;
function ResetPlayers ()
{
transform.position.y = 0;
playersAreReady = false;
yield WaitForSeconds(1);
playersAreReady = true;
}
function Update ()
{
if (playersAreReady == true);
(Input.GetKey(moveUp));
}
rigidbody2D.velocity.y = speed;
if (playersAreReady == true);
(Input.GetKey(moveDown));
{
rigidbody2D.velocity.y = speed *-1;
}
It still does not reckgonize that the boolean is false and it has to wait for one second but it doesnt wait for any ammount of time
– KainalexIt doesnt reckgonize that when the function "ResetPlayers" is called that the boolean is false for one second it continues without waiting for one second.
– KainalexNothing in your code calls ResetPlayer(), so nothing is reseting 'playerAreRead'. When debugging a problem line this, start with something simple. Just have a function called in start and verify the values are changing.
– robertbuI have another code that calls it but when it is called it only resets the y position to 0 but it does not call the playersAreReady false
– KainalexI'd have to see the rest of the script and how things are being called. As a guess, you are likely calling ResetPlayers() from inside of Update() or some other function that gets called a number of frames. The result is that you stack up a number of coroutimes. But that is only a guess.
– robertbu