Created
October 27, 2017 09:33
-
-
Save rdeioris/141e1013cee3b467fb29250e2131553f to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
public class FindBestMineral : MonoBehaviour | |
{ | |
// Use this for initialization | |
void Start() | |
{ | |
} | |
public Mineral GetNearestMineral() | |
{ | |
Mineral bestMineral = null; | |
float distanceFromBest = float.MaxValue; | |
Mineral[] minerals = GameObject.FindObjectsOfType<Mineral>(); | |
foreach (Mineral mineral in minerals) | |
{ | |
if (!mineral.wild) | |
continue; | |
float distance = (mineral.transform.position - transform.position).magnitude; | |
if (distance < distanceFromBest) | |
{ | |
distanceFromBest = distance; | |
bestMineral = mineral; | |
} | |
} | |
return bestMineral; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment