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!
[27291-screen+shot+2014-06-04+at+11.11.47+pm.png|27291]
2 Answers
2Load 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);
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.
Exactly what I needed, thanks so much! :)
– Tipdude501actually 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
– Tipdude501I decided to use OnTriggerEnter instead of GetKeyDown and it works fine
– Tipdude501hey, 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.
– TekksinSame issue
– Tipdude501