- Home /
Load Custom Scene
So I put a reload script on a plane beneath the level in case the player fell off, Just a really simple Application.LoadLevel script. This script can only be used for this one level though. Is there a way to make a customizable scene to load? In other words, does unity have a variable type for scenes? Thanks!
Answer by Tekksin · Jun 05, 2014 at 03:39 AM
in javascript it would be:
var nextLevel : String; //make sure the s is uppercase. Unity sometimes likes to make it "string" instead of "String" (which matters)
function Update(){
Input.GetKeyDown("R"){
Application.Load(nextLevel);
}
}
Go into your inspector and name the empty string variable (nextLevel) to whatever your desired next level's name is.
I'm pretty sure you don't want it to load a random scene, but rather a particular scene, but if you actually wanted something random to be loaded, you would assign the names of your other levels to numbers, and then do a random.range function. The number picked from random.range will correspond to the number that has been assigned to that level, and will load it up.
actually I'm now having an error when I use this; when I press play the character controller acts as though it's disabled and I can't control anything or move
I decided to use OnTriggerEnter ins$$anonymous$$d of Get$$anonymous$$eyDown and it works fine
hey, sorry, it might be because I made the R capitol lol. It should be lowercase "r". Try that if you want, and less us know if you are getting the same error.
Answer by Kiwasi · Jun 05, 2014 at 03:30 AM
Load level only takes string or int.
However if you know the name of the level you want to call you can do this:
// You can dynamically change the value of nextLevel however you like
string nextLevel = "TheNameOfTheNextScence";
// This will call whatever level you have specified
Application.LoadLevel (nextLevel);
Your answer
Follow this Question
Related Questions
Setting variable as type "Scene" 4 Answers
My life counter is not updating 1 Answer
Loading Scene on a series of events 2 Answers
Load scene on button press 4 Answers
Loading player location in a scene 2 Answers