I need a number of objects in each of my scenes to do something when the player is within a certain distance. Would it be best to attach a script to each object which checks the distance to the player, or attach a script to the player which loops and checks the distance to each object?
Target platform is android if it matters.
Thanks in advance!
public class Example : MonoBehaviour
private float range = 10.0f;
private Transform t;
private Transform player;
private void Awake()
t = this.transform;
player = GameObject.FindGameObjectWithTag("Player").transform;
private void Update()
print(player.name + " is " + Distance().ToString() + " units from " + t.name);
print("Player not found!");
private float Distance()
return Vector3.Distance(t.position, player.position);