Let’s say that I have a game object called thing, with a script attached to it called Health, and it’s tag set to “Thing”.
Lets say the script contains 1 variable, and at it’s value changes from thing, to thing.
public float health;
Now let’s say that there are several of the same game object (Thing) present in the scene at one time, clones perhaps, and I wanted to find out which game object (Thing) had the most health from another script at any given time. This new script would hold something like this: (the area with the comment is what I cannot figure out).
GameObject thing;
GameObject ThingWithMostHealth()
{
GameObject[] theThing;
theThing = GameObject.FindGameObjectsWithTag("Thing");
foreach (GameObject aThing in theThing)
{
//How do I find the thing with most health?
}
return thing;
}
Thanks for any help!