1 개의 강의

목차

Restricting the Trigger Condition

[Note]

Before engaging this section, please complete the parent section - Trigger Conditions.

When a Trigger has been added to a game object, it will report all encounters with other Triggers and Colliders to the AkTriggerEnter function. This means that unless you specify what type of Colliders or Triggers you are looking for, a game objects like the 301_Coin will play the Pickup_Coin Event for every other intersecting Trigger, and not only when the player is entering the Trigger to pick it up. One way to solve this, is by adding a AkTriggerEnter script to the 301_Coin game object.

When you've set an AkEvent to AkTriggerEnter, the AkEvent will look for a AkTriggerEnter script on starting the game.

In the AkTriggerEnter component you'll find a Trigger Object property. If the property is empty, it will listen to each and every collision. By adding a game object to this property, you will restrict the component to only react to that specific game object, thereby ignoring all other game objects.

[Note]

The AkTriggerEnter's Trigger Object cannot be assigned with game objects from a different Scene. If you need that in your own game, one method would be to make a custom script and find the game object once it's available.

Let's now add the AkTriggerEnter script to the Coin, so it will only trigger when the Player is picking it up.

  1. In the Hierarchy, select the 301_Coin game object.

  2. In the Inspector, click Add Component.

  3. Search for 'AkTriggerEnter' and select it.

    In the AkTriggerEnter component, look for the empty Trigger Object property. As the Adventurer is the one doing all the hard work of picking up items, let's choose the Player. Without populating the Trigger Object property, all game objects will be detected.

  4. In the Hierarchy, click and hold the Player game object and drag it into the Inspector > AkTriggerEnter component > Trigger Object property.

  5. Click Play and pick up the Coin.

    Notice that the Coin pickup sound is only posted when the player is picking up the Coin.

  6. Press ESC to open the WAG menu and click Play again to exit Play mode.