Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from unitycoder/gist:9a67e9bd559fb622d0e2
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save JT5D/a80c18d30371e8e2cc3e to your computer and use it in GitHub Desktop.

Select an option

Save JT5D/a80c18d30371e8e2cc3e to your computer and use it in GitHub Desktop.
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