I want the player to start the game on a random level each time they play. How do I do that? Thank you.
@Elijaht8 I’m guessing you have pre-made levels that you want the player to be randomly spawned into one of these. If you make each level into it’s own scene, you could load each scene randomly each time the player starts the game. Name each scene with a level in it ‘level1’, ‘level2’, level3’, ect. The we use a script that tells the game to randomly pick a level.
//Javascript
var RandomNumber : float;
function Start () { //When The Game Starts...
RandomNumber = Random.Range(1,5); //Pick Number between 1 and 5: 1, 2, 3 or 4
if (RandomNumber == 1) { //If The Number Is 1...
Applacation.LoadLevel("level1"); //Go To The Scene Titled 'level1'
}
if (RandomNumber == 2) { //If It's 2...
Applacation.LoadLevel("level2"); //Go To 'level2'
}
if (RandomNumber == 3) { //Ect...
Applacation.LoadLevel("level3");
}
if (RandomNumber == 4) { //Ect...
Applacation.LoadLevel("level4");
}
}
Attach this script to any game object in the first scene that is loaded and it SHOULD randomly pick a level and load it. Don’t hurt me if I’m wrong…
Two main lines used:
Application.LoadLevel()
Random.Range()