Unity – Rotate GameObjects

Rotate x frame

DRAG AND DROP this script over a object in the Hierarchy:

#pragma strict

function Update ()
{
         transform.Rotate(Vector3.back);
}

Rotate x frame

Rotate x seconds

#pragma strict

public var turnSpeed : float = 5f;

function Update ()
{
         transform.Rotate(Vector3.back, turnSpeed * Time.deltaTime);
}

Time.deltaTime -> it converts to rotate x seconds
turnSpeed -> speed of the rotation (it is a public variable, you can try to change his value inside Inspector!)

Rotate X Y Z

#pragma strict

public var turnSpeed : float = 20f;

function Update ()
{
         // -----------------------------
         // 2D Rotation XY plane
         // Rotate clockwise Z
         transform.Rotate(Vector3.back, turnSpeed * Time.deltaTime);         
         // Rotate anticlockwise Z
         transform.Rotate(-1*Vector3.back, turnSpeed * Time.deltaTime);
         
         // -----------------------------
         // 3D Rotation XZ and YZ
         // Rotate Y
         transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
         transform.Rotate(-1*Vector3.up, turnSpeed * Time.deltaTime);
         // Rotate X
         transform.Rotate(Vector3.right, turnSpeed * Time.deltaTime);
         transform.Rotate(-1*Vector3.right, turnSpeed * Time.deltaTime);
}