Yes i have something that calls the function “ResetPlayer” My boolean which is “playersAreReady” is not being called to be true or false in the update"
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;
(Input.GetKey(moveUp)); (Input.GetKey(moveDown)); are both varriables in unity and i set them to certain keys such as w and s playersAreReady its suposed to check whether its true or false
(Input.GetKey(moveUp));returns a boolean, but you're not assigning the result to anything, so it's pointless. playersAreReady is only checking for true, not true or false, as I pointed out. And you still haven't addressed the fact that you have semicolons following the conditional statements, AND I've just noticed that your brackets are unbalanced, so I'm surprised this script is compiling at all.
tanoshimi code is the best written best guess for what you need. If you are still having the Boolean problem then that issue is probably caused somewhere else. I would accept his answer and start a new question when you have a better idea where the problem might be.
@tanoshimi: I would suggest to add another else at the end of your else-if-chain and set the velocity to 0 there. Otherwise once a button is pressed the rigidbody will either move up or down and can't stop. Maybe that's what the OP want, but it seems a bit strange.
Is the reset players function being called in the function update. It may be being called more than once and not have time to wait for seconds.nuse a for loop to make sure it is called once.
reset players function is being called by another script
simply do this if (playersAreReady == true ){ if(Input.GetKey(moveUp)) rigidbody2D.velocity.y = speed; if (Input.GetKey(moveDown) rigidbody2D.velocity.y = speed *-1; }
what do you mean by is not being called
– 767_2(Input.GetKey(moveUp)); (Input.GetKey(moveDown)); are both varriables in unity and i set them to certain keys such as w and s playersAreReady its suposed to check whether its true or false
– Kainalex
– tanoshimi(Input.GetKey(moveUp));returns a boolean, but you're not assigning the result to anything, so it's pointless. playersAreReady is only checking for true, not true or false, as I pointed out. And you still haven't addressed the fact that you have semicolons following the conditional statements, AND I've just noticed that your brackets are unbalanced, so I'm surprised this script is compiling at all.