void FindClosestEnemy(GameObject target) {
if (openBattle == true )
{
GameObject gos;
gos = Object.FindObjectsOfType(typeof (Stats_Script));
GameObject closest;
float distance = Mathf.Infinity;
Vector3 position = transform.position;
foreach (GameObject go in gos) {
Vector3 diff = go.transform.position - position;
float curDistance = diff.sqrMagnitude;
if (curDistance < distance) {
closest = go;
target = closest;
distance = curDistance;
}
}
// return closest;
}
}
Above is the code I’m trying to adjust.
after the line gos = Object.F… I want to narrow the GameObject Array down to GameObject’s with a bool set to true. Any other object should be discarded.
How can I do this? `
//(gameObject.GetComponent