- Home /
OnTriggerEnter2D problem?
Hello everyone! Okay so I have this small project working on, a 2D platformer, I'm still new to unity so this might be a little stupid.. Anyways, my problem is that i'm tryiing to make a small code that respawns my player every time he collide with an object with deathObj tag I tried using OnTriggerEnter on another project before and it worked perfectly (3D game) but now it doesn't seem to work at all. This is the code im using: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerDeath : MonoBehaviour {
void OnTriggerEnter2D(Collider2D deathObj)
{
if (deathObj.gameObject.CompareTag ("deathObj")) {
Debug.Log("You are dead!");
//for now im just trying to print this message in the console but nothing happens..
}
}
}
Also I've set up the tags on unity so that shouldn't be the problem. Thanks!
Answer by OneCept-Games · Jan 03, 2018 at 04:00 PM
How is your collision matrix set up?
Also, do you have a Rigidbody2D and Collider2D component on your object?
Answer by LeeXxE · Jan 03, 2018 at 04:04 PM
Well that was so stupid of me. I've added a collided 2D but forgot the rigidBody2D. Thank you very much! Now its working!
Your answer
![](https://koobas.hobune.stream/wayback/20220612145734im_/https://answers.unity.com/themes/thub/images/avi.jpg)