- Home /
Other
Restart Level not working...
So, what I'm trying to do is,an exploding coin, that would restart the level when you colect it. here is my code:
var coinExplosion : Transform;
function OnTriggerEnter (info : Collider)
{
if (info.tag == "Player")
{
var effect = Instantiate(coinExplosion, transform.position, transform.rotation);
Destroy(gameObject);
yield WaitForSeconds(0.5) //Time for the explosion to end
Application.LoadLevel("Level1");
}
}
The coin explodes and everything, but the level doesn't restart... Tell me if you need more info. Thank you in advance,
Mato
Answer by AlucardJay · May 10, 2014 at 10:24 AM
You are destroying the gameObject, so it cannot wait for 0.5s because it is not there anymore! You need to rethink how you are going to call Application.LoadLevel
please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.
Why would you want to Destroy the GameObject if you reload the scene anyway? And you may use: Application.LoadLevel(Apllication.LoadedLevel);
now you can reuse it for every Level you have
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Problem when creating a projectile for a weapon. (FIXED) 1 Answer
Pause Button Help 2 Answers
How does Unity "read" JavaScript code? 3 Answers
What is wrong with my script? 1 Answer