hello everyone, im trying to create a minimap, and for it i need an array that contains all the objects i want in the minimap (in this case the planets). Im using the following code:
foreach(GameObject item in GameObject.FindGameObjectsWithTag("Planet")){
if (Vector3.Distance(gameObject.transform.position, item.transform.position) < dist &&
markers.Contains(item) == false){
markers.Contains(item) == false){
GameObject go = new GameObject ("Marker_" + item.name);
go.transform.parent = transform;
go.transform.localPosition = item.transform.position/dist;
markers.Add(go);
}
the problem is when i execute the code it adds the items in the sceene every frame. i need it to be dinamic, you know in case an enemy is near. any siggestions are much apreciated, thanks in advanced