Every GameObject in Unity has a Transform component. It is the only component that cannot be removed because it defines where the object is, how it is oriented, and how big it is in the game world.
What is Transform?
The Transform component stores three fundamental properties of a GameObject:
Position: Where the object is located in 3D space (example: 5 units right, 2 units up)
Rotation: Which direction the object is facing (example: 90 degrees to the right)
Scale: How big or small the object is (example: twice the original size)
Here are the most common ways to work with Transform in C#:
The transform variable is always available in any Unity script and refers to the Transform component of the GameObject the script is attached to. Vector3 is used for position, rotation angles and scale values. For rotation, Quaternion.Euler() converts simple degree angles into Unity's internal rotation format.
World Space vs Local Space
Understanding the difference between these two is crucial:
World Space: Absolute position in the game world. Use when moving an object to a fixed location like (0, 0, 0).
Local Space: Position relative to the parent. Use when attaching a hat to a character's head.
Example:
World space places the object at an absolute coordinate in the game world. Local space places the object relative to its parent's position – if the parent moves, the child moves with it. For objects without a parent, local space and world space behave the same.
Common Mistakes
Using degrees directly in transform.rotation: Rotation uses Quaternions, not Vector3. Use Quaternion.Euler() instead.
Modifying transform.position.x directly: Position is a struct, assign a whole new Vector3 instead.