Grabbing a vector3, from another object's Transform

Hello! I’m pretty new to Unity, and I’ve been pouring over the scripting reference trying to answer my own question, but something just doesn’t seem to be clicking in my head.

In a nutshell, this is what I’m trying to do:

I need a Vector3 in a script to be equal to the transform.position of a separate game object.

I can’t seem to wrap my head around the proper syntax for using a component from a different GameObject. This is the only thing I haven’t been able to figure out on my own, but I figured I needed to break down and ask the community.

I appreciate any answers I can get,

Thanks!

You need to get access to that other game object somehow. It can be by name, or by tag, or because you dragged and dropped it into a public variable in the current script. One example:

var myVector = GameObject.Find("Other").transform.position;

‘Other’ is the name of the other game object. ‘Other’ must exist or this line of code will throw and error.