Trying to wrap my head around transform.position w/o an object reference.

Hi,

I’m fairly proficient in 2D C# with XNA, but have recently dived into Unity as I feel it is far more useful in the long run. However, I’m having a complete noob moment right now. I can’t seem to wrap my head around the idea of transform.position without an object attached before it.

For instance, here’s some example lines of code from a tutorial I’m working through (they don’t go together. I just picked them out randomly where I saw a transform.position or something of the sort).

inputMovement = objPlayer.transform.position - transform.position; or

if ( Vector3.Distance(objPlayer.transform.position,transform.position) < 1.2f ) or

transform.position = new Vector3(transform.position.x,0,transform.position.z); or

transform.rotation = Quaternion.LookRotation(inputRotation); or

transform.eulerAngles = new Vector3(0,transform.eulerAngles.y + 180,0); or

transform.position = new Vector3(transform.position.x,0,transform.position.z);

How does it know what object I’m referring to? I’m so used to having to do object.position in XNA for everything, but I see transform.position on its own all the time. What am I missing here? I feel like it’s such a simple concept and I am just overlooking something…

Well, the object in question is the gameobject to wich the script is attached.
you might even use this.transform.position if it makes it clearer.

if you are not using it in a monobehaviour attached to a gameobject, you are right, there is no implicit transform position to use.

Ok that makes a lot more sense. this.position.transform actually does completely clear that idea up for me. Thanks a lot :).