I'm using Unity 3 to build my game. I have a basic GUI button that when clicked, I would like the user to be taken to a random level. There are 10 levels in my game. Below is a copy of the code I'm trying to implement.
function OnGUI()
{
// Make a background box
GUI.Box(Rect(10, 10, 100, 90), "Oracle");
if (GUI.Button(Rect(20, 40, 80, 20), 9)) ;
{
Application.LoadLevel(Random.Range(0, 9));
}
}
It's not happening. I've also tried:
function OnGUI()
{
// Make a background box
GUI.Box(Rect(10, 10, 100, 90), "Oracle");
if (GUI.Button(Rect(20, 40, 80, 20))) ;
{
Application.LoadLevel(Random.Range(0, Application.levelCount 9));
}
}
I've never used the Random.Range function before and somewhat confused at the proper format.
Also I have EZ GUI available and was wondering if I could enter the correct Random Range script into the 'script' dropdown or 'script with method' drop down work it, as I'd rather use a custom button. Any assistance would be greatly appreciated.