Rotating only one axis ?

I’m quite new to Unity -
I want to rotate a box’s Y axis using transform.rotate, but I need the X/Z values to remain at 0.
However when I apply the rotation, the X and Z values change too.
Is there a way to prevent that?

Try this

 transform.Rotate(Vector3.up* Time.deltaTime);

You can do like hirenkacha said or you can do:

transform.Rotate(0, 1, 0);

They do basically the same thing. Hirenkacha’s solution allows for smooth rotation regardless of computer performance (which is better). I am simply posting this solution as it shows what Vector3.up is actually doing.

this code is in js

#pragma strict

public var speed : float = 4.0;

function OnBecameVisible () {
	enabled = true;	

function OnBecameInvisible () {
	enabled = false;	

function Update () {
	transform.Rotate( 0.0 , Time.deltaTime * speed , 0.0 );

just attached the script to the object and select the speed in the inspector view and you are good to go.