- Home /
How to make something happen over time?
I made this script that teleports a collider to a certain transform after a certain amount of hits. I was wondering how I could make it so then the collider is destroyed and then spawns at the transform after an amount of time. Here is my script so far:
var lives = 5;
var spawnPoint : Transform;
var seconds = 5;
function OnTriggerEnter(){
(lives) = (lives) - 1;
if((lives) == 0){
gameObject.transform.position = spawnPoint.position;
}
}
Answer by robertbu · Jun 06, 2013 at 01:51 AM
You would be better off just disabling it and re-enabling it at some future time:
var lives = 5;
var spawnPoint : Transform;
var seconds = 5;
function OnTriggerEnter(){
(lives) = (lives) - 1;
if((lives) == 0){
Invoke("LiveAgain", 2.0);
gameObject.SetActive(false);
}
}
funciton LiveAgain() {
gameObject.transform.position = spawnPoint.position;
gameObject.SetActive(true);
}
This will wait 2.0 seconds before moving it an re-enabling it.
Thanks for the new script. I changed it a bit and it works fine!
Your answer
Follow this Question
Related Questions
how do i make my spawn system spawn every 2 seconds then wait 10minutes? 3 Answers
Instantiate 1 at a time at each transform in array 1 Answer
Why not can't spawn the object? 1 Answer
Instantiated object is destroyed in scene, but still logs as existing in console. 1 Answer
i need to destroy prefab clones 1 Answer