Game Development Reference
Listing 4.7 Script to Register a Collision on a Triggering Collider
function OnTriggerEnter (obj : Collider)
obj.gameObject.tag = "Untagged";
Step 4. Play. When the balls go through the cube collider it causes the
OnTriggerEnter() function to run. When a collider is set to be a trigger
only, it does not cause any collisions in the physics engine and therefore
the OnCollisionEnter() and similar functions do not work. For each
collision function there is an equivalent set of trigger functions. When
the balls are below the white line they will no longer be moveable
by the mouse.
Step 5. To complete this game we need to add a scoring mechanism.
We will use a trigger collider at the entrance to each beaker to count
the balls falling into them. Add four spheres to the Scene and resize
and position them like corks in the top of each beaker as shown
in Figure 4.8 .
Fig 4.8 Plugging the top
of a container with colliders.
Step 6. For each sphere, remove the Mesh Filter and Mesh components,
as we only require the Sphere Colliders. For each ensure that the Is Trigger
value is ticked.
in Listing 4.08 .