- Home /
reset level on collision
Ok, so what I want to do is to make it that when ONLY the player hits a specific object it reset that level. I have tried many scripts for this but can't seem to be able to get any of them to work, they will either reset the level when any object hits it or they just don't do anything.
Please help
-Ampler Games
Answer by aldonaletto · Aug 22, 2012 at 04:35 AM
Usually, you should check the player tag or name in the collision code - but be aware that there are several combinations (rigidbody hits something, character controller hits a collider, character controller enters a trigger) with different procedures.
The most common case is a character controller entering a trigger (trigger script):
function OnTriggerEnter(other: Collider){ if (other.tag = "Player"){ Application.LoadLevel(Application.loadedLevel); } }Another possibility is a character controller colliding with a collider - in this case the event is sent to the character controller script, thus you must check the other object's tag or name:
function OnControllerColliderHit(hit: ControllerColliderHit){ if (hit.transform.name == "ResetGameObject"){ // compare the object name Application.LoadLevel(Application.loadedLevel); } }Finally, if the character is a rigidbody, use OnCollisionEnter in the other object's script:
function OnCollisionEnter(col: Collision){ if (col.transform.tag == "Player"){ Application.LoadLevel(Application.loadedLevel); } }
NOTE: Remember to set the correct tag or name in the appropriate object (target object in the second case, player in the 1st and 3rd)
Thanks heaps, I have been trying to get this to work for a while. Now it works
help i have lava with the tag lava i want if the player with the tag player hit the lava that scene restart please help
help i got lava with the tag lava and i want if the player touch the lava that scene restart can you help i us unity 5
Answer by help00686 · Nov 14, 2018 at 09:32 PM
Where does this code go please
if u use this one function OnTriggerEnter(other: Collider){ if (other.tag = "Player"){ Application.LoadLevel(Application.loadedLevel); }}
then u need to place it on the object that can kill the player.... make sure to give the player object the tag Player
Answer by NaturedOne · May 05, 2019 at 02:56 AM
If anyone else runs into this,
Application.LoadLevel(int);
is obsolete, you'll want to use:
SceneManager.LoadScene
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Trying to animate on collision, Help Please. 0 Answers
Script help please 1 Answer
Analysing player metrics help 0 Answers
On Collision, Create a Cube? 1 Answer