- Home /
I need help with collision detection event
Hi guys,
I have a 2D object that I call "Player" and have this script attached to it so I can detect any collision it makes with other objects
public class PlayerCollision : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider col) {
Debug.Log ("1");
if (col.gameObject.name == "Rocket") {
Debug.Log ("2");
}
}
}
The two Debug.Log() calls were only for testing purposes. However, as I tested, neither returns a result, so I'd assume the event was never triggered.
I made sure to tick "Is Trigger" on "Player"'s collider, as you can see from the below screenshot
The other object, which was supposed to collide with "Player" is called "Rocket", and below is its collider
I don't know where the problem might be, please lend me your aid! All efforts are appreciated. Thank you very much !
Answer by whydoidoit · Feb 21, 2014 at 05:00 PM
You need OnTriggerEnter2D I believe.
Wow, surprisingly it's true. I didn't know OnTriggerEnter() couldn't be used in 2D context. Thank you very much !!!
Your answer
