- Home /
teleporting player after time runs out
I'm something of a noob scripter so if the answer is obvious have mercy on me... I've been having trouble figuring out a way to teleport the player after a timer runs out. I've been trying it with this countdown script since there are objects you can collect to increase the time in my game and this makes that relatively easy, i just cant seem to get it to teleport the player. heres what i have so far
var o_countdownTimer : countdownTimer;
var f_timerdone = timerDone;
var teleportTo : Transform;
o_countdownTimer = GetComponent(countdownTimer);
o_countdownTimer.setStartTime(10.0);
o_countdownTimer.setTimerDoneAction(f_timerdone);
o_countdownTimer.setTimerState(true);
function timerDone() {
transform.position=teleportTo.position;
}
in place of the first script on the link.
Thanks in advance! ^^
going to need more of your code to figure out what's going on here. You essentially just copy and pasted the code from that link and modified one line. You're setting the transform.position equal to teleportTo.position, and since teleportTo is declared as a Transform, there is no reason this shouldn't work.
You could be calling the function in the wrong place, not calling it at all, not setting objects in the scene correctly, etc.
Answer by theafters3 · Dec 19, 2011 at 09:03 AM
Thanks both but it turned out the GUItext it was attached too was teleporting, heres my solution if anyone needs it in the future xD
var o_countdownTimer : countdownTimer;
var f_timerdone = timerDone;
var teleportTo : Transform;
var teleportee : UnityEngine.GameObject;
var vartime = 0;
o_countdownTimer = GetComponent(countdownTimer);
o_countdownTimer.setStartTime(vartime);
o_countdownTimer.setTimerDoneAction(f_timerdone);
o_countdownTimer.setTimerState(true);
function timerDone() {
teleportee.transform.position=teleportTo.position;
gameObject.active = false;
}
Answer by fafase · Dec 19, 2011 at 07:22 AM
Mmm, maybe you have it but I dont see it, in the update you need to countdown a variable, varTime for example each frame and have a
var varTime = 100.0;
if(varTime == 0)
{
transform.position = (0,0,0)
}
Then you use a collision function to increment
function OnControllerColliderHit(hit:ControllerColliderHit){
if(hit.gameObject.tag == "itemTag")
{
varTime+=100;
Destroy(hit.gameObject);
}
}
this function checks every frame if your player is colliding with the tagged item. You need to tag your item so that it matches what you write inside the brackets. In case you don't know about tagging, click on the object and on the top of the inspector there is a tag menu, click and choose a tag or edit new one. Then if the if statement returns true, your varTime gets 100 more and the item is destroyed so that the player cannot just recharge endlessly.
Hope that helps.
I would +1 you if it let me, even though this wasn't the exact answer it really really helped me a little bit later on. xD
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Script to teleport player (Beginner here) 0 Answers
Teleport Help. 2 Answers
how to add a sound to this script 3 Answers
Infinity Hallway 1 Answer