- Both objects have a Rigidbody attached to them
- Neither objects Rigidbody component are “Kinematic”
- The two objects have box colliders attached, not mesh colliders
- The script is being called from the object with the box collider attached
- Both object layers are ticked in the Settings > Physics panel
- Neither box colliders have “Trigger” set to true
- The objects cannot pass through each other in world space
- The code is attached to a prefab that is already instantiated in the world.
However, the following code does not execute:
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Entity")
{
hitDetected = true;
collision.gameObject.GetComponent<EntityBehaviour>().isDead = true;
GameObject.Find("PlayerController").GetComponent<ShipController>().AddScore(100);
}
}
There is no “Collision!” appearing in the Debug log, and none of the code runs.
Unity 5 is not broken. What am I missing?
Np! I'm glad it helps :)
– tadadosi