- Home /
how to quit game after 2 second when object collide another?
in my game when car collide some objects will end game but i want it to end the game after 2 second not immediately and i need to modify my script... function OnCollisionEnter(car : Collision) { if (car.gameObject.tag == "hit")
Destroy(gameObject); Application.Quit();
}
function OnCollisionEnter(car : Collision) {
if (car.gameObject.tag == "hit")
{ Destroy(gameObject); }
yield WaitForSeconds(2.0);
Application.Quit();
}
Put the yield WaitForSeconds(2.0) and Application.Quit(); in the if condition since you want the game to be over only when collided object is car.
Answer by Darsh2019 · Jan 02, 2015 at 11:05 AM
create new function
IEnumerator MyScript() {
yield return new WaitForSeconds(2);
}
wherever you want delay in your function write this : StartCoroutine(MyScript());
more Details : http://docs.unity3d.com/ScriptReference/WaitForSeconds.html
Your answer
Follow this Question
Related Questions
How to activate a script from a collision? 1 Answer
Destroy Turret with machine Gun 0 Answers
Collision with steep terrain 1 Answer
Stuck in Car tutorial - Wheels 0 Answers
How to see object through collision? 0 Answers