OnCollisionEnter () and OnTriggerEnter() both are the methods of the Collider Class. Both are used to detect collisions when colliders enter the collision but both perform differently and cause different events.
OnCollisionenter() is used to create Collisions between objects. Gameobjects collide with each other and get repelled by their forces.
To use OnCollisionEnter(), a collider must be attached to the gameobject and its IsTrigger property should unchecked and in order to receive a physical collision event one of the colliding gameobject must have rigid body attached to itself.
In above example code, a Collision Class is passed as parameter for OnCollisionEnter () which contains information about the other colliding object, contact points, relative velocity, rigid body of colliding object etc. If we dont need any such information we can use use OnCollisionEnter () without any parameter.
OnTriggerEnter() is used to detect collision but it does not act as solid body , rather allows the gameobjects to pass through them. To use OnTriggerEnter() , the IsTrigger property of the collider should be checked. To get trigger event to work properly a rigid body must be attached to one of the colliding gameobject.
In above example code, a Collider Class is passed as parameter in OnTriggerEnter() which contains the information about the triggering gameobject, if you want trigger to work for all gameobjects passing through it then eliminate the parameter.