Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created July 1, 2017 20:25
Show Gist options
  • Save unity3dcollege/7dfab83b9c092046518987357831d4e5 to your computer and use it in GitHub Desktop.
Save unity3dcollege/7dfab83b9c092046518987357831d4e5 to your computer and use it in GitHub Desktop.
var coinsByDistance = allCoins.OrderBy(Vector3.Distance(transform.position, t.transform.position);
yield return new WaitForSeconds(1f); // Vector3.Distance hasn't called once, everything's still deffered
if (Input.GetKeyDown(KeyCode.A))
{
foreach (var coin in coinsByDistance) // This iteration makes the LINQ statement execute.
{
coin.DoSomething();
}
}
else
{
Debug.Log("Player didn't press 'A'... so nothing's causing the LINQ statement to be executed");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment