- Home /
Teleporting script won't work
I am making a slender game and I made a script that makes slender man teleport every amount of seconds, but the slender model never teleports. This is the script:
var secondsToTeleport = 10;
var slenderPrefab : Transform;
var backSpawn : Transform;
var numberOfPages : int;
var levelToLoad : String;
static var lol = 0;
if(lol == 1){
Invoke("SlenderTeleport", (secondsToTeleport));
}
function Update(){
if(lol == numberOfPages){
Application.LoadLevel(levelToLoad);
}
}
function SlenderTeleport(){
slenderPrefab.position = backSpawn.position;
Invoke("SlenderTeleport", (secondsToTeleport));
}
I know that it doesn't have to do with the "lol" variable because the level still changes after the amount of pages are collected. So how do I make it so then the slender model teleports?
Answer by Memige · Jun 18, 2013 at 09:13 PM
Your check for lol==1
is only run once at script compilation, move it inside of your update function if you want it to be an ongoing check, or inside a Start function if you want it run every time a new object of this type is instantiated.
Thanks for the tip! It's fixed now. I used an invoke repeating under the start function.
Answer by bubzy · Jun 18, 2013 at 08:22 PM
"lol" will never equal 1
Yes it will. Like I said in the question, it's a global variable. I have a script on each page that adds to the value of "lol" each time someone clicks on it.
I know that it is because the level changes after the right amount of pages are collected.
Your answer
Follow this Question
Related Questions
If String is in List Then... 2 Answers
Spawning System 1 Answer
Teleport Script by KeyDown for fast Level testing 2 Answers
Spawning issues 0 Answers
How to check where a player is looking 2 Answers