- Home /
Question by
TheDonkeyQueen · Feb 19, 2014 at 05:46 PM ·
2dcollidertrigger
Trigger versus collision?
I have a death trigger that I've applied to an object. When the player collides with the object the player are supposed to die, but instead player moves right through without triggering the event. Why is this? When I have Is Trigger on the player moves through, when I turn it off the player collides with the object but nothing happens. Also this is for a 2d game if that is useful information to have.
using UnityEngine;
using System.Collections;
public class DeathTrigger : MonoBehaviour
{
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
// Player entered red zone, reload game.
Application.LoadLevel(0);
}
}
}
Comment
Best Answer
Answer by haim96 · Feb 19, 2014 at 06:41 PM
did you check the box "isTrigger" in the collider component?
$$anonymous$$ake sure to use OnTriggerEnter2D and Collider2D if you are using 2d colliders.
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
// Player entered red zone, reload game.
Application.LoadLevel(0);
}
}