is there a better way to do this?


i am trying to get minimap icons to follow a random number of instantiated objects.

this seems like it should be very simple yet it’s proving to be way out of my league.

my current attempts is:

#pragma strict

var ship : Rigidbody;
var asteroid : Rigidbody;

var aIndS : Transform;
var height : float;

private var sCount = 0;
var aCount : float;
var aEnable = false;

var rForce : float;
var pForce : float;
var area : float;

function newShip()
	var newShip = GameObject.Instantiate(ship);

function newAsteroid()
	var randP = Random.value * pForce;
	var randR = Random.value * rForce;
	var rPose1 = Random.insideUnitCircle * area;
	var rPose2 = Vector3(rPose1.x,0,rPose1.y);
	var newA = GameObject.Instantiate(asteroid);

	newA.position = rPose2;
	var newAIndS = GameObject.Instantiate(aIndS);
	aIndS.transform.position = newA.position;

function Start () 
	var a : int = 0;
	var s : int = 0;

the important bit being in function newAsteroid()

obviously this function only runs once so when the objects move to their newly instantiated target they never update position.

what i can’t figure out is how to make only

aIndS.transform.position = newA.position;

repeat via Update, Invoke repeating, ect… because the position is dependent on

    newA.position = rPose2;

all i can think to do is make some secondary script with some complicated targeting system based on nearest target. this seems really scripting heavy. is there a better way to do this?


Your code is hard to read, the variable names seem unintuitive to me.

But based on your headline i’m guessing what you want is to store the location of all the asteriods in the game so you can use there locations to track them on a minimap?

what you want is a list of transforms (you may even choose to have a list of game objects either way, you can get an object from a transform or a transform from an object, but if you think you’ll want to do other things with every asteriod later maybe have game objects since you’ll be starting in the game object and not the transform)

in the new asteriod function add the new asteriods transform to the list of transforms.

You can do a foreach (transform asteriod in asteriodlist)

to iterate through the list and do stuff like get each asteriod.transform.position and use that for a minimap.