- Home /
Making a loadlevel script that saves a lot of space
Hey guys I am getting into unity.
I made a loadlevel script that will save me a lot of time.I made this so that I do not have to make a script everytime I make a new scene.
but I have problems,here is my script:
#pragma strict
var levelname : string;
function Start () {
}
function OnTriggerEnter () {
Application.LoadLevel("levelname");
}
Hopefully you can help me.
Answer by ncallaway · Jan 11, 2014 at 05:00 PM
The problem is the quotes around the levelname parameter that you pass to Application.LoadLevel(). The quotes mean you are passing in the literal string "levelname" every time, such that Unity will always try and load Assets/levelname.scene.
If you get rid of the quotes, you will then be passing the variable levelname:
#pragma strict
var levelname : String;
function OnTriggerEnter () {
Application.LoadLevel(levelname);
}
Apologies, "string" should have been capitalized ("String"). I make this mistake a lot in Unityscript because C#'s value-type of string is lowercase.
I've edited the answer above to use the capitalized version "String".
Your answer
Follow this Question
Related Questions
Can't click gameobject when over another trigger? 1 Answer
Load next level 0 Answers
LoadLevel Health Question. 1 Answer
Level dont loaded, after enter a Trigger BoxCollider 1 Answer
Why does my game go straight to game over when game starts? 2 Answers