Completing the feature by adding voice over
Now to complete finish the entire game feature, we need to quickly inform the players about this special game mechanic. Provided in this course is an voice over which directs the player to right click to throw a coin. This voice over is going to be triggered via a collider once the player reaches a certain point.
And just to top off the coin throwing feature, we are going to add an throwing animation to Darren (our player) when the player right clicks.
Setting Up the Animation:
In the Animator window (Windows > Animation > Animator) we are going to drag and drop a new state called the “Throw”. From there we are going to connect the “Throw” state from the Any State. This is because we want the throw animation to occur at any interval of the game play. Then we also want the Throw state to connect back to the Idle state after it has completed its full animation length.
Next we set up the parameters to trigger the animation and apply it in the conditions.
In the Player script, since we already have an handler for the animation component, we can access the newly created parameter easily. In the section where you right click mouse button down, we are going to insert the Set trigger script with the string “Throw”.
Now every time you right click, the throw animation should play.
Trigger the Voice Over:
On the scene, there should be an provided empty box collider or if there isn’t, simply make an 3D cube object and deselect the Mesh renderer to make the collider hollow.
Make sure to check “Is Trigger” within the box collider component and add an Rigidbody component to allow the object to collide with the Player object.
Next we are going to create a new C# script which contains the ability to check for collision and play an audio clip upon trigger. This script is design to be applied to various voice over trigger objects in the future so it has reusability.
Voice over Script:
In the voice over script, you are going to create an new public handle which will contain future voice over audio clips. Then you are going to create a new On trigger Enter event where the method is checking for name tag of “Player”. In the IF statement, if the player tag has been detected, we will play the audio source.
Back in Unity, we are going to apply the script to the voice over object, and also add an audio source component. Drag in the required audio clip to the audio source component and then drag the audio source component to the slot in the script.
Finally, within the Audio Source component, uncheck “Play On Awake” because we only want to play this audio when we pass the trigger point.