Position of a GameObject

Hello,

I was wondering to find the position of a gameobject with a certain tag on the ‘x’ co-ordinate. I wrote a code and found that it did not give the answer I was expecting.

var player = GameObject.FindGameObjectsWithTag ("Player");
var dis : float;
function Update () 
{
dis = player.transform.position.x;
print(dis);
}

Request:

Is my code right, if not how could I find a position of a gameobject which is not attached onto a script.

Thank you very much.

Actualy, what you’re caling is GameObject.FindGameObjectsWithTag (“Player”). With an “s” at the end of Objects. That means your player is an array even if there is ony one object. So you should do dis = player[0].transform.position.x;

Asking the position of a instatiated clone is pretty simple.

var clone : GameObject;
var player: GameObject;

clone = Instantiate(player,transform.position,transform.rotation);

print (clone.transform.position);

The last line gets the current position of the clone.

Also take a look at instantiate for more info:

Instantiate

Edit: Btw, you said it does not give the answer you are expecting, but what answer are you expecting?