Write values in list-like thing.

Hi guys!

The title may sound weird, but here is what i want. So in my game i have lots of objects and every object has a script called Info which contains a variable objectName. So how can i get this variable for every single object which is closer than some value to the player and make a list with the object. (Im making a space game and I got this idea from the EVE online UI)

Thanks. -Arnold

If I am understanding your intention correctly. You could add a functionality on your info script to append itself to a static list. Doing it this way makes for better code than doing a search for all the GameObjects in the scene.

	using System.Collections.Generic;
    ...
	static IList<Transform> nearTargets=new List<Transform>();
	Transform playerPosition;
	float maxRange=10.0f;
	bool inRange=false;
    ...
	void FixedUpdate(){
		float distance=Vector3.Distance(playerPosition.position,transform.position);
		if(inRange){
			if(distance>maxRange){
				inRange=false;
				//remove from list
				nearTargets.Remove(transform);
			}
		}else{
			if(distance<maxRange){
				inRange=true;
				//add to list
				nearTargets.Add(transform);
			}
		}
	}

then you can just dot into it from any other code file with
info.nearTargets.position;