Week 8 - Unity Sounds Insert
- Anton Byankov
- May 19, 2019
- 2 min read
25.03.2019
With the coming of the Easter Holidays and the lack of active actors to work with, I decided to focus this week's attention on the audio input into Unity. Something that seems quite complicated and frustrating to me, considering that coding is involved, but everyone has to step out of their comfort zone sooner or later in order to progress.
From the initial research I have done on guides and tutorials of Audio Input, I cannot say that I am particularly certain what is required of me to do, but I am willing to invest some time in order to get the grasp of it.
29.03.2019
After taking some time with studying the Unity program and its various applications, I've made the conclusion that inserting an audio file is not that hard, even if it seemed as such at first. Considering that there are already created components that you just need to position in a correct way, I've come up with the following simple guidance when including an audio file into the choice-based mechanic of dialogue boxes that we've chosen for the game.

Open the project.
Insert the audio file(s) or folder.
Create New Game Object.
Rename the above to the appropriate reference (HopeChoice1, HopeChoice2, etc.)
Add Component "AudioSource". For the sake of choice-based mechanic, we will add three. One will be responsible for the line "Ridge Cottage?", second for "Help?", and a third one for "I'm Hope".
Create New C# Script.
Add the script onto the game object.
Open the script.
Create a Unity Audio Clip Class.
Insert the following code: public class AudioScript : MonoBehaviour { public AudioClip HopeLine1Clip; public AudioSource HopeLine1Source; void Start () { HopeLine1Source.clip = HopeLine1Clip; } void Update () { If (Input.GetKeyDown(KeyCode.JoystickButton2)) HopeLine1Source.Play(); } }
Save the script.
Follow the same procedure for the rest 2 AudioSource components, assigning HopeLine2 to KeyCode.JoystickButton3 and HopeLine3 to KeyCode.JoystickButton1.
Go back to the Unity Editor.
Go to the Game Object (HopeChoice1)
On the audio file, there must be public variables for each HopeLine Clip and Source.
Drag the appropriate music files into the Clip, and AudioObject (HopeChoice1) into Source.
Play.
This way, if you press X on the Joystick, you'll hear the appropriate line assigned to that AudioClip, while the other two choices (Y and B), will, naturally, take you to the other two choices.
Commenti