- Home /
OnCollisonEnter2D.
I am trying to make a 2d platformer. I have an object that when the player collides with it, the game restarts. For some reason it doesn't work. I set a simple Debug.Log statement to test it. But, it just doesn't work. Here's the code
using UnityEngine;
public class Collision : MonoBehaviour {
private void OnCollisionEnter2D(Collision2D collisionInfo) {
if (collisionInfo.collider.tag == "Lose") { Debug.Log("lose");
} }
}
Answer by xxmariofer · Jul 29, 2020 at 06:59 AM
make sure one of the objects have a rigidbody 2d both have a collider, and add a debug out of the tag in case the tag is wrong spelled or not applied, also make sure colliders are not set to trigger
Your answer
![](https://koobas.hobune.stream/wayback/20220613004317im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
"Dash-Move" only work some times. 1 Answer
Having some stuck issues on the 2D infinite runner 0 Answers
Player getting stuck between grounds 0 Answers
How to create soil or sand?? 1 Answer