Wednesday, October 23, 2013

Unity Sound Example - Random Volume

A quick demo that makes use of audio.volume and Random.Range() to randomise the volume of a triggered sound in Unity.

In short, the process is:
• Find an in-game object that currently triggers a single sound
• Find the script that is associated with that object that triggers that sound
• Find a reference to audio.Play(); within the script
• Randomise the volume of the audio source in the line before audio.Play(); e.g. audio.volume = Random.Range(0.1, 1.0);
• Save the script and run the game again
• Note that the parameter of volume is an amplitude multiplier (e.g., 1.0 is 100% amplitude, 0.5 is 50% amplitude etc).