Collision callback function not called

一笑奈何 提交于 2019-11-28 13:11:28

Reasons why OnCollisionEnter() does not work:

Collison:

1.Rigidbody or Rigidbody2D is not attached.

At-least, one of the two GameObjects must have Rigidbody attached to it if it is a 3D GameObject. Rigidbody2D should be attached if it is a 2D GameObject/2D Collider.

2.Incorrect Spelling

You failed to spell it right. Its spelling is also case sensitive.

The correct Spellings:

For 3D MeshRenderer/Collider:

OnCollisionEnter

OnCollisionStay

OnCollisionExit

For 2D SpriteRenderer/Collider2D:

OnCollisionEnter2D

OnCollisionStay2D

OnCollisionExit2D

3.Collider has IsTrigger checked. Uncheck this for the OnCollisionXXX functions to be called.

4.The script is not attached to any of the Colliding GameObjects. Attach the script to the GameObject.

5.You provided the wrong parameter to the callback functions.

For 3D MeshRenderer/Collider:

The parameter is Collision not Collider.

It is:

void OnCollisionEnter(Collision collision) {} 

not

void OnCollisionEnter(Collider collision) {}

For 2D SpriteRenderer/Collider2D:

6.Both Rigidbody that collides has a isKinematic enabled. The callback function will not be called in this case.

This is the complete collison table:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!