-1
\$\begingroup\$

For some reason my collisions are not working. This is what the code I have.

void OnCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "wall")
Debug.Log ("It worked");

}

When my object I have the script attached to hits the wall, I don't get a Debug.Log, if anyone knows what I am doing wrong please let me know!

\$\endgroup\$
1
  • \$\begingroup\$ Ensure the wall object has the correct tag on it as well as going through alaslipknot's answer. \$\endgroup\$
    – Savlon
    Oct 27, 2014 at 3:47

2 Answers 2

1
\$\begingroup\$

One of the followings is causing the problem :

  • One of your colliders doesn't have a Rigidbody2D attached to it, as it says in the documentation, in order to get collisions works, one of the two object must have a rigidbody component
  • You are checking "isTrigger" and expecting OnCollision response, if your collider set to trigger then you should use "OnTriggerEnter2D" instead
  • Everything works but your console doesn't shot any messages, make sure the "bubble" icon is pressed in the console window, to be sure just print something in the Start() method and see if it shows up.
\$\endgroup\$
-1
\$\begingroup\$

The problem turned out to be that my objects didn't have colliders. Anyways thanks for the help!

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .