OntriggerEnter
The OnTriggerEnter function is never called because of two main reasons. First, the enemy
BoxCollider Component should be marked explicitly as a trigger volume. This ensures the Enemy object
is ignored by the standard Unity physics system and only receives notifications when objects enter
its volume. Second, the Ammo object must have a RigidBody Component. This component is required
because OnTriggerEnter events are generated only when RigidBodies enter the trigger volume.
1.Setting the BoxCollider as a Trigger Volume
To get started at fixing these issues, select the Enemy object in the scene, and in the Object Inspector
enable the Is Trigger check box,
2Adding a RigidBody Component
Next, we need to add a RigidBody Component o the Ammo object.
Doing this adds a RigidBody Component to the ammo and makes the object compliant to the
Newtonian laws of physics. This means that if you test run your game now with the RigidBody at its
default settings, and fire your weapons, the ammo will fall to the ground under the effects of gravity
instead of shooting upward toward the enemies as they should do. This behavior totally transforms
the appearance of our ammo, from looking like fiery balls of energy to orange tokens and innocuous
confetti. To complete the configuration for the RigidBody we must enable the Is Kinematic check
box. Doing this allows our object to keep many of the benefits and qualities of a RigidBody (including
the ability to invoke OnTriggerEnter events) but makes it immune from the normal physical laws:
from gravity, friction, inertia, and more (see Figure 3-20).
Enabling Is Kinematic for a RigidBody makes it immune from most aspects of the Unity Physics System. It indicates
that developers will animate and move the object manually

浙公网安备 33010602011771号