There are a lot of messages in Monobehaviour, a total of 62!
In addition to a series of functions that must be followed in the life cycle of the script, there are two other sets of more frequently confusing messages: collisions and triggering.
According to 3D and 2D objects, and divided into collision: collision, collision2d. Trigger: Trigger, trigger2d.
Taking the three-dimensional object as an example, the following experiments were done to test the ONCOLIISIONXXXX collision message and the ONTRIGGERXXXX trigger message.
Experimental simulations:
1. Create object A and object B, respectively, so that object A is above object B
2. When object A has a rigid body assembly, a force motion is added to object A (rigidbody. Addforce), when object A does not have a rigid body assembly, the displacement Motion (transform) is added to object A. Translate).
3. The gravity-affected option of the rigid body is removed in case the object has a rigid body assembly.
4. Print collision and trigger messages for object A and object B in different combination scenarios, and observe the object crossing situation
The experimental results are as follows:
Study room time to, first come here, go home to fill the conclusion!
Unity Collision Message (ONCOLLISIONXXXX) and trigger message (ONTRIGGERXXXX) Call context