Throughout Allegro Kingdom, you will find various crates and barrels that each have a chance to spawn a Coin when destroyed. When a Coin is instantiated, it will fall to the ground, ready to be picked up by the Adventurer. To pick up a Coin, the Adventurer can simply run through it and the Pickup_Coin Event will be played. To trigger this Event, you'll need to use the AkEvent script. Here are the steps to perform.
In the Unity menu, select Audiokinetic > Certification > 301 > Lesson 1 > Trigger Conditions.
Let's find and add the 301_Coin from the Wwise Adventure Game project's Assets folder.
In the Project view, search for '301 Coin'.
Drag the 301_Coin game object into the Scene view.
Use the Move tool ('W') to place the 301_Coin on the ground in the Training Area.
Make sure the green Trigger on the Coin game object is not overlapping the Player.
What is a Collider/Trigger? To detect interactions between game objects in Unity, you can use Colliders. There are many types of Colliders (Box, Sphere, Capsule, etc.), and they are most often used to define the physical shape of an object's Mesh (shape) in order to hinder intersection. A Trigger is a Collider that detects collisions, while it also allows other Colliders to pass through it. The Collider will not draw the shape of the Mesh (like a stone is drawn with flat polygon surfaces), but use the mesh invisibly to define the size and shape of the Collider.
If the player were overlapping the Sphere Trigger, the coin would automatically be picked up at Scene start. Instead we want the player to go pick up the coin, and hereby show that when entering the Sphere Collider set to Is Trigger in gameplay, the sound will activate. If you are not seeing a sphere outline like in the image above, make sure the Sphere Collider component is open in the Inspector. Simply click the name to expand it.
While a Trigger is technically a Collider set to Is Trigger, we will simply refer to them as Triggers.
You will now add a sound to the 301_Coin game object. However, instead of using the Wwise Picker you will learn how to locate and add the needed premade scripts manually, so you will be aware of how to do so later in the certification.
In the Inspector, select Add Component.
Search for 'AkEvent' and select it.
In the Event Name property, expand Events > Player > General and double-click on Pickup_Coins.
When the game starts, the Pickup_Coin Event will now be posted with reference to the 301_Coin game object. Next, you'll need to assign a method for triggering the Event. On the 301_Coin game object, you'll find a Sphere Collider, which has been set to Trigger. In the AkEvent > Trigger On property, you have a selection of the most common methods for triggering sounds. To trigger the Pickup_Coin Event when entering the Sphere Trigger, you can use the AkTriggerEnter option. Notice that the Trigger On property is set to Start. To change all previously selected conditions to AkTriggerEnter only, first reset all by selecting Nothing, then select AkTriggerEnter.
In the Trigger On property, select Nothing.
Open it again and select AkTriggerEnter.
Click Play and run into the Coin.
Did you notice that the Pickup_Coin was posted multiple times? While you have configured the AkEvent component correctly, the problem is that the Trigger area responds to every game object entering the Trigger. When starting the game, the Trigger will first detect the ground itself and post the event. Later, the same event is posted again when the player enters the Trigger.