I'm trying to make it so an object checks how far it is from any object from a list. I have this script so far but it seems to only work with the closest one and ignores all others
public var objects : GameObject[];
function Start () {
objects = GameObject.FindGameObjectsWithTag("Tree");
}
function Update () {
for (var object in objects) {
if ((transform.position - object.transform.position).magnitude < 10) {
//Do something
} else {
//Do something else
}
}
}
↧