Rotating an object in world space.

Here’s a very simple code snippet, for use in rotating a camera SkyBox. This is the simplest code I can think of to demonstrate what I am trying to do, as apparently I’m terrible with this math…

function Start()
{
	//transform.localRotation = Random.rotation;
}

function Update()
{
	transform.Rotate(Vector3.right, 10.0f * Time.deltaTime, Space.World);
}

This simple script works perfectly, until the commented line is un-commented in the Start() function.

The issue is that the Start function is randomly rotating the object and changing it’s local rotation, obviously. The update function is not properly rotating the object in world space because the objects local rotation is being rotated on the wrong axes.

It looks like i need Quaternion math to rotate properly when the local rotation is randomized. Can someone help me with the math to properly modify the rotation as desired?

Then this should work:

function Update() {
    transform.Rotate(0, 5, 0);
}

EDIT : deals with the world-space vs local-space issue :

looking back to the issue of world space vs local space, you probably need to change the Vector3 (world space) to a transform (local space) in the Update :

function Start() 
{
	transform.localRotation = Random.rotation;
}

function Update() 
{
	transform.Rotate(transform.right, 10 * Time.deltaTime, Space.World);
}

.
first answer just with Random.rotation workaround :

#pragma strict

function Start() 
{
	//var rotX = Random.Range(0, 360);
	//var rotY = Random.Range(0, 360);
	//var rotZ = Random.Range(0, 360);
	//transform.localRotation = Quaternion.Euler(rotX, rotY, rotZ);	
	// or just simplify with : 
	transform.localRotation = Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360));
}

function Update() 
{
	transform.Rotate(Vector3.right, 10 * Time.deltaTime, Space.World);
}

http://unity3d.com/support/documentation/ScriptReference/Quaternion.Euler.html

OK, well I found the issue and saved my sanity… My method above was fine, rotations were happening as I wished but there was another influence still active and also playing with the localRotation of the objects.

This was an error on my side, everything actually works as it should. I appreciate everyone’s help and apologize for wasting your time on this.