Hey there!
I’ve got a problem with an if statement in an if statement.
The code in the inner if statement should start execute when the two if statements are true, right? ( doesn’t work either)
In my case, when they are false. Why doesn’t it work in my script below?
When only one condition is false, the while loop gets executed!
I did a lot of testing, and I’m sure the two variables are doing what they have to do. (They are false when I want them to be false and vice versa).
Does anyone know the problem here?
Please, help me out
distance = Vector3.Distance(transform.position, boxPuzzlePosition2.transform.position);
if(!boxFinished){//this condition...
if(!targetScript2.pushed){//...and this condition need be false to execute the while loop
while(distance > 0){
transform.position = Vector3.Lerp(transform.position, boxPuzzlePosition2.transform.position, Time.deltaTime * 0.85);
distance = Vector3.Distance(transform.position, boxPuzzlePosition2.transform.position);
yield; //yielding to this just means it won't just reach the destination instantly
}
}
}
distance = Vector3.Distance(transform.position, boxPuzzlePosition3.transform.position);
if(!boxFinished){//this condition...
if(!targetScript2.pushed){//...and this condition need be false to execute the while loop
while(distance > 0){
transform.position = Vector3.Lerp(transform.position, boxPuzzlePosition3.transform.position, Time.deltaTime * 0.85);
distance = Vector3.Distance(transform.position, boxPuzzlePosition3.transform.position);
yield; //yielding to this just means it won't just reach the destination instantly
}}
}
}