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.
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;