The white cube is the Player.
The blue cube has a Rigidbody.
The red cube has just a Box Collider.
A script with these lines of code is attached to the Player cube:
If we run the application and move the player cube around we get messages written into the Console.
Why is that the case?
GameObjects with a Rigidbody do collide with each other. Therefore, OnCollissionEnter() will be called. However, both GameObjects will need a Rigidbody Component.
If your GameObjects just have Colliders (or just one of your GameObjects has a Rigidbody component), OnTriggerEnter() will be called by Unity.
For this, at least one GameObject will need a Rigidbody component. Otherwise, it won’t work and the function will not be called.