- Home /
OnCollision2D will not work for me
I am testing OnCollisonEnter2D and it doesn't seem to want to work for me. I have box collider 2d and rigidbody2d's on both of my game objects and again, it fails to send a message to the console.
using UnityEngine;
using System.Collections;
public class CollisionAndResetSystem : MonoBehaviour {
void OnCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "Cube")
print ("hit");
}
}
I took this strait from the Scripting API and it doesn't want to work.
did you create a tag named "Cube" and specify it to your object (Tag does not have anything to do with object name)?
Are you sure you have the right settings in Physics matrix ?
Are you sure trigger is not checked in your collier ?
Answer by Hexer · Jul 27, 2015 at 01:20 AM
Physics collision is disabled if isTrigger is checked. Make sure it is turned false. And the opposite object refered as coll should ofcourse have the tag "Cube" attached to it.
isTrigger is disabled and 'coll' is in fact named 'Cube'
Doesn't matter what it's named. It needs to be tagged "Cube".