How get position from a game object?

Im trying to make a cam follow a gameobject, and I don’t know how get the position of the object. helpme please

You can find the object by the object tag.

GameObject.FindGameObjectWithTag("Your_Tag_Here").transform.position;

Or you can find the object by the name of the object.

GameObject.Find("Your_Name_Here").transform.position;

Hope that works :wink:

If the script you are using is atached to the object for which you want the position it is as simple as

Vector3 bar = transform.position;

otherwise you need to get an instance of the object of which you want the position:

foo = Object_In_Scene.GetComponent();
Vector3 bar = foo.position;

It’s all a matter of relativity.

“Read The Fine Manual.” ~Waz

https://docs.unity3d.com/Manual/ControllingGameObjectsComponents.html

Read The Fine Manual.

Hello @gabosuelto! if you want to make the MainCamera follow a GameObject, you can write a C# Script, but the simplest thing to do is drag your MainCamera onto the GameObject.

You can learn it from : GameObject.Find