- Home /
Loading level using a string created through code.
Whats up!
I have a simple question can you load a new level using a string created in a script? e.G:
var LevelToLoad : String = "";
function Update (){
if(Input.GetButtonDown("Jump")){
LevelToLoad = "LevelOne";
LoadLevelFunction ();
}
}
LoadLevelFunction (){
Application.LoadLevel(LevelToLoad);
}
But it just says unknown identifier ´LevelToLoad´.
I could use some sort of loadlevel +(=) 1;
But it would be much more easy if you can fill Application.LoadLevel with a string created by the user.
Thank, you for your time.
Answer by G_Sacristan · Jul 14, 2011 at 07:12 PM
Add ALL levels you want to Load: Build Settings-> Scenes To Build
private var levelToLoad: String="";
function Update()
{
if(Input.GetKeyDown("space"))
{
LoadLevel("levelToLoad");
}
}
function LoadLevel(p: String)
{
Application.LoadLevel(p);
}
there is nothing incorrect with your code, but this is my way to do this ($$anonymous$$or change)
Answer by DaveA · Jul 14, 2011 at 10:38 PM
I can't see anything wrong with your code, you should be able to do this. As SCape_games said, make sure you have them checked in your Build Settings so they are in fact included. But I don't think that would account for that particular error message.
One note though: It's common to Capitalize the First letter of a Function , and have small case for the first letter of a variableName to keep them cognitively different. Just a convention most of us follow.
Answer by Waz · Jul 14, 2011 at 10:51 PM
You're missing "function" in front of LoadLevelFunction declaration.
Your answer
Follow this Question
Related Questions
Weird behaviour in Application.LoadLevel() 0 Answers
Teleporting/application.loadlevel 1 Answer
Play Scene help 1 Answer
Making a loadlevel script that saves a lot of space 1 Answer
Application.LoadLevel problem 1 Answer