- Home /
Question by
zadeh79 · Nov 03, 2019 at 07:57 PM ·
conditional
Problem with conditional ALWAYS RETURNS TRUE
For some reason no matter what value I use in my conditional (enemydistance < n OR enemydistance > n) it is ALWAYS RETURNING TRUE
If anyone can please provide some insight into what might be going on with my conditional. Thanks!
enemydistance[3] = Mathf.Sqrt(Mathf.Pow(aienemy[3].transform.position.x - controls.birdposition.x, 2) + Mathf.Pow(aienemy[3].transform.position.y - controls.birdposition.y, 2));
if (enemydistance[3] < 1.0f) ; //ALWAYS RETURNS TRUE FOR UNKNOWN REASON
{
anim2 = controls.rb.gameObject.GetComponent<Animator>();
anim2.Play("playerdeath");
}
Comment
Best Answer
Answer by petur · Nov 03, 2019 at 10:05 PM
Remove the ";" at the end of the "if" condition, that makes the compiler think it is unrelated to the instructions in brackets below.
if (enemydistance[3] < 1.0f)
{
anim2 = controls.rb.gameObject.GetComponent<Animator>();
anim2.Play("playerdeath");
}
Your answer
Follow this Question
Related Questions
If using a conditional-situational menu, such as a pop-up, must wait till next OnGUI? 2 Answers
Conditional Custom Editor with Popup 1 Answer
Is it not possible to include "if-then" conditionals within foreach loops? 1 Answer
How to change color on multiple game object when button is clicked 1 Answer
If statements with Lists 1 Answer