Transform Checking on all Array Objects (JS)

Hello Unity helpers,
The scenario goes as follows:

I have Ghost Objects being created with a specific ‘y’ value on the transform.position
I have an array which finds all the Ghost Objects in the scene

GhostFound = GameObject.FindGameObjectsWithTag("GhostTag");
for (var i=0; i < GhostFound.length; i++)
  {
    SpecificGhost = GhostFound*;*

}
So my question is, how would I get all of the values of the y transform position on all the ghosts in the scene (from that array), and if at least one of the y values matches the number ‘860’, it sets the ‘GhostonPlat’ boolean to true?
I really do appreciate your help!

Direct comparison to floats often fails to to floating point imprecision. You can use Mathf.Approximately(), or if there is more chance of imprecision (i.e. moving using Time.deltaTime(), you can look for range. So:

for (var i=0; i < GhostFound.length; i++)
{
    var go = GhostFound*;*

if (Mathf.Abs(go.transform.position - 860.0) < someThresholdValue) {
go.GetComponent(Ghost).GhostonPlat = true;
}
}
This assumes that the script with the ‘GhostonPlat’ variable is named ‘Ghost’. Change as appropriate. ‘someThresholdValue’ will be some small value you set that defines how much the position can vary from 860.0 and still be considered 860.0.
[http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html][1]
[1]: http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

First of all, I’d highly recommend NOT doing FindGameObjectsWithTag (or any version of Find anything) pretty much ever, but definitely not during an Update loop. I’d instead recommend adding them to some sort of variable thing when you create them.

Ok, sorry about that. Answer time.

var MagicNumber = 860;
var GhostYs = [];
GhostFound = GameObject.FindGameObjectsWithTag("GhostTag");
for (var i=0; i < GhostFound.length; i++)
{
   SpecificGhost = GhostFound*;*

GhostYs.push(SpecificGhost.transform.y);
if (SpecificGhost.transform.y == MagicNumber)
{
GhostOnPlat = true;
break;
}
}
Fairly simple comparison; grab the y value of the transform and compare it (to a variable or const, not a numeric literal cough cough), set the bool and break out of the loop. Break terminates the loop early; if you care about checking every Ghost even after finding one, you can leave it out and the code should work just the same.
You can see I’ve pushed the Ghost Y values onto an array as well, though if all you needed was to check that one boolean, it’s not really necessary.
EDIT: @robertbu has an excellent point. Definitely use some form of float approximation for equals regardless of what you do.

Simpler solution:

private var GhostsFound : GameObject[];
private var GhostonPlat = false;

function Start ()
	{
	GhostsFound = GameObject.FindGameObjectsWithTag("GhostTag");
	for (i in GhostsFound)
		{
		if (i.transform.localPosition.y == 860)
			{
			GhostonPlat = true;
			}
		}
	}

Sometimes in Unity the locations of gameObjects changes by 0.000000001. So checking directly equals on a transform is not recommended. You should probably check like this:

if (i.transform.localPosition.y > 860.5 && i.transform.localPosition.y < 859.5)