Im working on a script to change levels after a certain amount of time has passed but im a noob when it comes to Java Scripting. I was wondering how to implement the script into my project. Do i attach it to an empty object in the level or something completely different. Can you guys help me out? Here is what i have so far.
var x = Time.timeSinceLevelLoad;
var timerlimit:int;
var zones: String;
function Timer1() {
if (x<=timerlimit){
x+1;
}
if (x == timerlimit) {
Application.LoadLevel ("zone2");
}
}
Thanks!
2 Answers
2
Do I attach it to an empty object in the level?
Sure. Sounds good to me, that's what I do for general purpose scripts like these.
You probably want to code it like this though:
var timeLimit : float = 60; // 1 minute timer
var nextMap : String = "zone2"; // Change this to next level for each scene.
Invoke("NextMap", timeLimit);
function NextMap() {
Application.LoadLevel(nextMap);
}
Or if you just want to go to the next map:
var timeLimit : float = 60; // 1 minute timer
Invoke("NextMap", timeLimit);
function NextMap() {
Application.LoadLevel(Application.loadedLevel + 1);
}
I know this is old but… THANK YOU I HAVE BEEN LOOKING EVER FOR THIS SCRIPT!
Awesome i will try this and see what happens! Thanks a ton!!
– anon69302355SO i attached the script to the empty game object but it won't attempt to change to the next level after the time limit passes. Any ideas?
– anon69302355I figured it out, i needed the correct build settings but it works perfectly! Thanks again man a big help for sure!!
– anon69302355Thank you so much Statement this little bit of code was a life saver
– kangta