Thursday, 4 May 2017

Outside the Box Project Beta Work - SFX Development

Coin Pick-Up

As art of general player feedback for the player anything that is interacted with in-game should produce a contextual sound. For the coins to provide feedback appropriately we required their sound to play when the player "picked them up", so to speak; this was done through 2 means. 
First, like most of the other SFX (Sound Effects) in the game, I created an empty gameObject at 0, 0, 0. This gameObject's purpose was to simply have a component of type Audio Source which would have reference to the appropriate SFX, in this case the coin pick-up SFX.


Then in the money pick up script I had to inform Unity that I would be coding/using Unity's audio script features by typing out "using UnityEngine.Audio", similar to whenever I need to code for the UI in Unity.
At first I simply tried to play the audio source during the OnMouseOver function, however that failed to work, despite playing the sound first on the hierarchy, as Unity was not able to find the audio source as the coin was destroyed.
So instead I decided to instantiate the empty gameObject with the coin pick-up SFX attached in the OnMouseOver function, play the sound and then destroy the instantiated container after the SFX had time to play in its entirety, so 2 seconds.



Defence Purchase




The defence purchase sound works in the same manner as the coin pick-up sound, the only difference between them is that the purchase sound is activated by clicking a button as opposed to mousing over something, like the coins.

Defence Upgrade:


Bullet Fire Updated:



The bullets get their contextual/appropriate sound they need to fire by accessing the AudioSource component on the gameObject the Defence Shooting script is attached to, which is every defence. The AudioSource is used just to project the sound and at what volume.

The actual sound is referenced from another GameObject as fireSound, and the AudioClip of the AudioSource component is set to fireSound. This way it's a standardised way of controlling the sound of the bullets, as all I have to do is feed in the appropriate SFX in the public variable fireSound and the Defence that has a reference to that sound will play it always.

This way, I can change the sounds were necessary with ease, by simply dragging and dropping the SFX in.



Defence Upgrade SFX Updated:

Later on, however, after finalising how the "Bullet's" would produce their sound it was no longer viable to play the Defence Upgrade sound as I had done so previously as the Audio Sources on every defence was taken over by the contextual "Bullet" SFX.

So instead I went back into the Upgrade Component Script, which managed and checked if the player could upgrade a Defence. And I set up a private AudioSource variable, which was set in start through GameObject.Find("Require Object Name") and then GetComponent<AudioSource>();

This found the Audio Source on the found GameObject, and then I set the AudioSource variable to play in the IF Statement that runs both should the player have enough money to upgrade and the player has pressed the Yes Button on the Upgrade Menu (the UI piece that pops up asking if the player would like to upgrade their defence).





No comments:

Post a Comment