- Home /
Add 2 Parameters in While loop
Can anyone please tell me how can i add 2 parameters in while loop in unity 5(I mentioned it because i don't if there is any new rule has cam for unity 5), i want to do something like this :-
while(attack<=0 && enemy>0)
{
}
I am trying but it's not working and not giving me the parameter autofill option after && , i think there is something wrong .
Answer by ZacGarby · Jun 25, 2015 at 08:27 PM
have an "if" inside the while, like this: while ( attack <= 0 ) { if ( enemy > 0 ) { // Do stuff here! } }
Perfect . Thanks , I just skipped that part for my game right now but will use while in next game . :)
It can work with and operator , but i think it maybe disturb in Or condition .
Answer by Hellium · Jun 25, 2015 at 07:29 PM
Nesting the loops won't have the expected result.
The "parameter" as you call it is a boolean condition (called expression). It's not abnormal to have an expression like this : (attack <= 0 && enemy > 0)
. It will return a boolean the will
statement will evaluate like any other boolean expression.
Just, make sure attack and enemy are numeric values.
What is the error raised by the compiler ?
I am pretty sure the error didn't come from the while loop then, but just above it.
Answer by RayJr · Jun 25, 2015 at 07:18 PM
you could try nesting them..
while(attack<=0 )
{
while(enemy>0)
{
}
}
Your answer
Follow this Question
Related Questions
While loop doesn't start again when condition is true 1 Answer
Making A 4 Barrel ShotGun! Need Some Help - UPDATE 3 Answers
Timed while loop? 0 Answers
Legacy Animations and Unity 5 - What's The Deal? 1 Answer
Trying to Loop A Function 2 Answers