My journey becoming a Unity game developer: Coin Distraction-Voice Over Trigger

Rhett Haynes
3 min readNov 10, 2021

--

Objective: Play an audio clip of Oliver telling Darren that he can use a coin to distract the guards when Darren moves through the Voice Over Trigger’s game object collider.

Darren walks through the Voice Over Trigger object to play the audio clip telling him to toss a coin.

This will be the last part of the Coin Distraction part of the game. We’re going to add an audio clip of Oliver telling Darren to use a coin to distract the guards.

Let’s start by creating a new C# script name Voice Over Trigger. Select all 3 Voice Over Trigger game objects, and drag the script onto the game objects. This will allow us to use a modular script to play the audio clips that will be assigned for each Voice Over Trigger game object.

Voice Over Trigger script added to 3 voice trigger game objects.

Inside the Voice Over Trigger script, we can delete the Start() and Update() functions since we won’t need them. Create a new variable with the Type AudioClip name audioClip which will hold the actual audio clip that will play when the player moves through the trigger game objects. We can use either the Public access modifier or the SerializeField field to place the audio clip into the script’s component slot.

Next, we will use the OnTriggerEnter() method to check IF the Player is using a Tag “Player” moved into the Voice Over Trigger collider. Use the CompareTag() method to find the Player tag because this method gives better performance over using the regular “Tag.”

If the Player collides with the Voice Over Trigger game object, use the AudioSource to PlayClipAtPoint using the audioClip variable at the Main Camera’s position in World Space. We’re using the Main Camera’s position to play the audio clip to hear clearly and with a consistent volume level.

Back in the Inspector, for these triggers to work they need Rigidbodies attached to them with the Use Gravity turned off for the OnTriggerEnter() method to work. Also, turn on the Is Trigger setting in the Box Collider component to allow the Player to move through the Trigger objects.

Voice Over Triggers are given rigidbodies for collisions and Is Trigger is turned on for each Box Collider.

Final thing we need to do is select each Voice Over Trigger game object, and drag the appropriate audio clip into each audio clip slot in the Voice Over Trigger script component. In this case, we need to select the Throw Coin VO Trigger game object and drag the Toss Coin Dialogue audio clip into the variable’s slot. Also, disable the Mesh Renderer for all the waypoints placed since we don’t need to see them any longer.

Audio clips added to each VO Trigger game object.

When Darren walks through the Voice Over Trigger game object, the Coin Toss Dialogue audio clip will play with Oliver telling Darren to use the coin to distract the guards.

Coin Toss Dialogue audio clip plays when Darren walks through the Voice Over Trigger game object.

The next part of the game we will work on is the Security Cameras being an obstacle for Darren to navigate.

--

--

Rhett Haynes
Rhett Haynes

Written by Rhett Haynes

Learning to become a Unity game developer.

No responses yet