- Home /
Death script problem
Why is my script doing nothing?
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
// Player entered red zone, reload game.
Application.LoadLevel(0);
}
}
}
Answer by Dblfstr · Feb 19, 2014 at 07:36 PM
Is your death zone a 2d collider? Does the player have a 2d collider? They both need to be the same collider I think. Meaning a Collider2D wont trigger in that OnCollisionEnter, because it is looking for a Collider (3D), not a Collider2D.
public class Example : MonoBehaviour {
void OnTriggerEnter2D(Collider2D other) {
if(other.tag = "Player")
{
//Do stuff
}
}
}
//2D Physics only
Answer by TutiBueno2 · Feb 19, 2014 at 04:03 PM
Just check if the object that you are attaching your script has the "IsTrigger" property checked on the collision component.
For whatever reason my Player can pass through the deathzone when deathzone is marked as trigger :/
Your answer
![](https://koobas.hobune.stream/wayback/20220613134031im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Death trigger 1 Answer
Time.deltaTime stops counting up, after the Player is destroyed 1 Answer
Script to detect a death fall 2 Answers
Death on impact with water 1 Answer
Best way to do gun reload and move sway 0 Answers