Transform

How to use the Transform component to Position, Rotate and Scale a GameObject!

The Transform Component determines the Position, Rotation, and Scale of each object in the scene. Every GameObject has a Transform.

It contains useful functions such as Rotate, LookAt and Translate. And also useful variables such as position, rotation and forward.

Examples

Shortcut variable

Because Transform is a common component, there is a shortcut property available to access it in any MonoBehaviour.

This will save you having to use GetComponent.

Using the shortcut:

public class Rotator : MonoBehaviour {

	void Update()
	{
		transform.Rotate(0, 1, 0); // Rotates the current GameObject
	}

}

Without using the shortcut:

public class Rotator : MonoBehaviour {

	private Transform _transform;

	void Awake()
	{
		_transform = GetComponent<Transform>(); // Get the Transform component on the current GameObject, and store it in _transform
	}

	void Update()
	{
		_transform.Rotate(0, 1, 0); // Rotates the current GameObject
	}

}

Notes