unity object position code example
Example 1: get position of any gameobject in unity
GameObject.Find("Your_Name_Here").transform.position;
Example 2: unity set position
GameObject.transform.position = new Vector3(x, y, z);
Example 3: unity c# transform position
GameObject myObject;
myObject.transform.position = new Vector3(x, y, z);
transform.position = new Vector3(x, y, z);
Debug.Log("x : " + myObject.transform.position.x);
Debug.Log("y : " + myObject.transform.position.y);
Debug.Log("z : " + myObject.transform.position.z);
Example 4: how to reference the position of a game object unity
private Transform player;
private void Start()
{
player = GameObject.Find("Player").transform;
}
Example 5: get position of gameobject unity
GameObject.FindGameObjectWithTag("Your_Tag_Here").transform.position;