What is Transform?
- Game Development course
- Beginner
- Lesson 37/83
- 4 min
Learn that the Transform component holds position, rotation and scale.
What Is Transform?
Transform is a component attached to every GameObject in Unity that defines its geometric state in a scene. Its three main properties are Position, Rotation, and Scale. These values determine where an object is, which direction it faces, and how large it is.
Transform
Position: (0, 0, 0)
Rotation: (0, 0, 0)
Scale: (1, 1, 1)These three properties control an object's placement and appearance in the scene.
The Three Main Transform Properties
Position determines an object's location, Rotation determines its orientation, and Scale determines its size. Each property contains three values for the X, Y, and Z axes. For example, a Scale value of (2, 2, 2) makes the object twice as large on all three axes.
Position = (3, 0, 2)
Rotation = (0, 90, 0)
Scale = (2, 2, 2)You can also change these values in the Transform section of the Inspector window.
Practice Print Transform Properties
Use the Start method in a Unity C# class to print the object's position, rotation, and scale separately in the Console window. Use Debug.Log and the corresponding Transform property for each value.
Starter code
using UnityEngine;
public class TransformInfo : MonoBehaviour
{
void Start()
{
// Print position, rotation, and scale.
}
}Sample solution
using UnityEngine;
public class TransformInfo : MonoBehaviour
{
void Start()
{
Debug.Log(transform.position);
Debug.Log(transform.rotation);
Debug.Log(transform.localScale);
}
}Expected output
(0.00, 0.00, 0.00) (0.00, 0.00, 0.00, 1.00) (1.00, 1.00, 1.00)
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which Transform property do you use to change an object's size?
- Scale Correct answer
- Transform
- Position
- Rotation
Explanation: Scale changes an object's size along the X, Y, and Z axes.
2 Specify the Object Rotation Property
string propertyName = "____";
string propertyName = "Rotation";
Explanation: Rotation is the Transform property that determines an object's orientation and angular state in the scene.
3 Transform Properties
| Term | Meaning |
|---|---|
Position |
Determines the object's position |
Rotation |
Determines the object's rotation |
Scale |
Determines the object's size |
Transform |
Contains the three main properties |