Created
January 4, 2015 21:41
-
-
Save unitycoder/9a67e9bd559fb622d0e2 to your computer and use it in GitHub Desktop.
LINQ: Pick closest transform from list of gameobjects
This file contains 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
using System.Linq; | |
.. | |
// get list of objects with tag "Player" | |
GameObject[] gos = GameObject.FindGameObjectsWithTag("Player"); | |
// get closest transform from gos[] array, into target variable, as transform object | |
var target = gos.OrderBy(go => (transform.position - go.transform.position).sqrMagnitude).First().transform; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment