Throwing Animation

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.

Connecting the “Throw” state from the Any state to the Idle state.

Next we set up the parameters to trigger the animation and apply it in the conditions.

From Left to Right: these are the trigger conditions from where Any State goes to Throw state and finally when Throw state goes into Idle state.

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.

The settings for the Voice over trigger

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.

We can also delete the rest of the unneeded start and update methods in this script.

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.

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Balancing Those Binary Trees

Handling Authentication and Authorization with Node

AngularJs and ReactJs

Strict equality v loose equality in JavaScript

The current state of Internet Explorer

Building a simple REST API: Introduction to NodeJS and Express.

React.js Fundamentals and Concepts

Set default value for <select> in Angular 2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

2D Player Animation (part 2)

Using Decals in Unity

VFX — Adding player thrusters and visual player damage

Galaxy Shooter 2D — New Enemy Behavior (Follow)