Created
July 1, 2017 20:00
-
-
Save unity3dcollege/060dd81a97e53a53a48013270432dbce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private GameObject GetNearestGameObject(List<GameObject> gameObjectsToConsider) | |
{ | |
float smallestDistance = Mathf.Infinity; | |
GameObject nearestGameObject; | |
foreach(var go in gameObjectsToConsider) | |
{ | |
var distance = Vector3.Distance(transform.position, go.transform.position); | |
if (distance < smallestDistance) | |
{ | |
smallestDistance = distance; | |
nearestGameObject = go; | |
} | |
} | |
return nearestGameObject; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment