Wednesday, October 23, 2013

Unity Sound Example - Random Pitch

A quick demo that makes use of audio.pitch and Random.Range() to randomise the pitch 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 pitch of the audio source in the line before audio.Play(); e.g. audio.pitch = Random.Range(0.5, 2.0);
• Save the script and run the game again
• Note that the parameter of pitch is a sound playback rate / ratio value (e.g. 1.0 is normal pitch, 0.5 is half pitch, 2.0 is an octave up etc).