Find the closest of two named gameobjects?
I would like to target the closest of two named gameobjects. For example, one enemy is called enemy1, and the other is called enemy2. How can I do something like this:
If (enemy1 distance from me < enemy2 distance from me) {
target = enemy1
}
else if (enemy2 distance from me < enemy1 distance from me) {
target = enemy2
}
Any idea how? Thanks
Comment
With those two you can get it done easily. http://docs.unity3d.com/ScriptReference/Vector3.Distance.html http://docs.unity3d.com/ScriptReference/Transform-position.html