- Home /
Why won't it end game on unity on contact with water
Here is my code #pragma strict
function OnTriggerEnter () { Application.Quit(); }
function OnCollisionEnter(other : Collision) { Application.Quit(); }
This is a script I made under the object water.
Have you tried adding Debug.Log statements into the those functions to see if the application actually gets there?
I have to ask; why are you trying to do this? No real game would quit on entering a collision, and you're not the first or even the fifth one asking how to do that.
i've changed it to restart on collision, so that when(the car) hits the water the game automatically restarts
PS. is there a way to replace my currently painted trees(on terrain) with a different tree but retain there position?
Answer by chris_taylor · Feb 28, 2014 at 06:50 PM
Make sure you have a collider and rigidBody on the object, also I suggest checking the tag to make sure you are hitting water
also I dont think Application.Quit does anything inside the editor
I've added a rigid body but which collider should I use- terrain?
If you are just using the built in unity water then add a box collider and scale it to the size and depth of the water and mark it as trigger