Unity Tutorial 07 (Semester 2)

 


Image from the tutorial

This week I did my final Ruby tutorial for the semester and I have to say it was a pretty good feeling. Up until this week my game has had no audio so this week I had to add some in. This week I learned about audio clips, audio listener and audio source. Audio clips are assets that you can import from an audio file such as MP3 and wav. Audio listener is a component that tells you where the listener is in the scene which is placed on the camera. Audio source is a component that allows you to play an audio clip where the GameObject is. The first thing I had to do was add in some background music. To do this I had to create a new GameObject called BackgroundMusic and add audio source to it. I then had to add in an audio clip called 2D MUSIC LOOP so that the music would play from the beginning to the end. I then had to add in the spatial blend slider and make it go all the way to 2D so that my music could be heard everywhere. I then had to add a one shot sound so that my audio would only play once when I collected a health object. To do this I had to create a new audio source and assign it the health collectible audio clip and uncheck the Play On Awake option. After this I had to add an AudioSource function to my script and call it PlayOneShot and add it to my Ruby GameObject. I then had to open my RubyController script and add a private AudioSource variable called audioSource and add it to the start function with GetComponent. I then had to add a function called PlaySound (AudioClip clip) and add audioSource.PlayOneShot (clip); I then had to open my HealthCollectible script and add collectedClip to my AudioClip function. I then had to add my collectible audio clip to my audio folder. I then had to add sound for when Ruby threw a cog or was hit by an enemy. To do this I had to follow the same process. I then had to make the sound diegetic meaning it could be heard by players within my game. To do this I had to open my Enemy robot prefab and add an audio source to it. I then had to add a clip to my audio folder called Robot Walking_Broken and check the loop setting. I then had to move my spatial blend slider to 3D. I then had to change the Max Distance volume from 500 units to 10 units. I then had to fix the attenuation. To do this I had to set my audio listener to z = 0. Then I had to select the camera and create a new GameObject called Listener and add my audio listener to it and set its coordinates to x = 0, y = 0 and z = 10. I then had to remove my audio listener component from my camera. After I finished this my game finally had audio and that was Ruby's Adventure finished. 

Comments

Popular posts from this blog

Introduction Post

My Favourite Game: Grand Theft Auto Franchise

Game Alpha