Objective: Describe when to use OnTriggerEnter or OnCollisionEnter.
OnTriggerEnter and OnCollisionEnter are C# components of game objects that detect interactions between objects. A collider is added to a game object to define the boundaries for interactions with other objects. A rigidbody should be added to a game object that moves to detect interactions. If physics are not used check IsKinematic in the rigidbody component. There are two major differences between OnTriggerEnter and OnCollisionEnter:
1. The collider or rigidbody conditions that will cause the script to execute. OnTriggerEnter requires both objects to have a collider with one having IsTrigger checked, and one of the objects must have a rigidbody. OnCollisionEnter requires a rigidbody or collider on both objects, and one of the objects is nonkinematic, i.e. IsKinematic is not checked. Below is shown the possible outcomes with force being added to the sphere rigidbody.
2. The component of the other colliding object that is accessed. OnTriggerEnter accesses the collider of the other colliding object. OnCollisionEnter accesses the collision of the other colliding object.
Use OnCollisionEnter if you need to access collision physics; otherwise, use OnTriggerEnter.