Space ship UI, multiple pointer that follow individual targets.

i have been searching for days trying to solve this.

What I want is to detect all objects with specific tags within triger check, and then I want a guiTexture to appear, follow and scale accordingly to distance (follow and scale is done) so all I need now is for the guiTexture to appear AND follow the right object.

The detection works.
“targetArrow” is the name of the guiTexture (which got an attached script(UIFollowTarget).


#pragma strict
var distanceToPlayer : float; 
var graf : GUITexture;
var nameN : String;
var namnet : Transform;

function OnTriggerEnter(trigger : Collider){


if (trigger.tag != "Player"){
Debug.Log("not me");}

  if (trigger.tag == 'HOSTILE') 
		//attempts to find and give name and transform
		nameN =;
		namnet = trigger.transform;
		//find the script name n give it to variable
		var script: UIFollowTarget = targetArrow.GetComponent(UIFollowTarget);
		//do stuff to other script
		script.targetName = nameN; = namnet;
		//this one gives error
		//i dont know what im doing
		var pointer : GUITexture;				
		pointer = Instantiate(graf.guiTexture);  


var target: Transform;		//found in other script
var targetName : String;	//found in other script
var color : Color;

function Update()
	  // place the GUITexture at the targets position:
	  transform.position = Camera.main.WorldToViewportPoint(target.position);
	  if (target.gameObject.tag == 'HOSTILE')
	  		//give color
	  		guiTexture.color =;
	  distanceToPlayer = Vector3.Distance(target.transform.position, Camera.main.transform.position);
	  //scale to distance
	  guiTexture.pixelInset.width = 100-distanceToPlayer;

If this is still a question. We resolved this by instantiating additional clones of a (you called them) UIFollowTarget prefab. So we have multiple clones in the scene as many as targets. Although you’ll have problem with targets leaving the viewport, because these will not render in the main camera, only when the object reenters the field of view of your camera.