Sounds muse

shot.png

Audio cues can play a huge part in games, ranging from minor sounds like a gun click to large and dramatic sounds like the usage of an ultimate ability. Unity3D helps in this by providing a 3D sound engine which we could use to our advantage.

The question I pondered while adding sounds to guns was that which agent should handle the sounds? I want the gun shot sound to be heard when the bullet was shot and an explosion sound to be heard when the bullet hit its target.

Audioplayonawake.png

The first problem was solved easily by setting the “Play On Awake” flag on for the gun shot audio source.

The second problem though, left me stumped for a while when the explosion sound just refused to play when the bullet was destroyed…

Then I realized again that the bullet was destroyed and the sound would not play after that. After thinking a while, it seemed that I had two ways of solving it. Either I disable the bullet after the hit, only enabling the audio source or I create a new item to play the clip, then destroy itself.

The first way was horribly messy, so I opted for the second one, adding a Sound_Handle script to the “Main” game object, then create an empty game object called “Speaker” to hold the Sound_Mech script.

Writing a special function which would be called whenever a sound needs to played by a placeholder source, the script, “Sound_Mech” is altered to hold the correct sound before I instantiate it.

While I’m not sure this is the best way, but I do need multiple audio sources so I guess this would work until I can think of something better.

 
0
Kudos
 
0
Kudos

Now read this

Tick Tock

Time is an important concept in games, controlling and constraining player actions so we could have a better game structure. From time to time, I had implemented a timer like this: class timer: public start=false public time=Time.time... Continue →