An if else statements inside my for loop is giving impossible print readouts.
void CheckDistance()
{
//Gets a list of all the heroes, nulls the ones that are too far away
//Or are the players hero.
//And it's really not working.
Hero = GameObject.FindGameObjectsWithTag("Player");
bool OneInRange = false;
if(Hero.Length > 1)
{
//Now we have to enabled each icon.
//And have it follow the appropriate guy...
for(int x = 0; x < Hero.Length; x++)
{
print("HERO CHECK:" + Hero.Length + x + (HeScript.MyHero).name + Hero[x].name);
if(Vector3.Distance(Hero[x].transform.position,transform.position) > 4 && gameObject != HeScript.MyHero)
{
print("HERO FAR");
}
else
{
print("HERO Close");
//Hero[x] = null;
}
}
}
}
But here’s what it prints out:
HERO CHECK/
HERO FAR/
HERO CHECK/
HERO CHECK
Which should be impossible since either the if statement is true and it prints HERO FAR or it isn’t and it prints HERO CLOSE.
But it somehow prints HERO CHECK and just skips it twice… I even commented out the nulling line and it still did the same thing.
I’m totally baffled, any ideas?
EDIT:
Just added a print statement (Print(“END FOR”)) to the end of the for loop.
Now it reads
HERO CHECK/
HERO FAR/END FOR/
HERO CHECK/
HERO CHECK
So basically it looks like it doing a full loop then… Something that I have no idea about.