Saturday, October 26, 2013

Unity Sound Example - Simple LFO Modulator

A quick demo that makes use of Mathf.sin(), Update() and a variable to modulate the pitch of an audio asset via an LFO.

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
• Create a variable at the top of the code for indexing the LFO, e.g.:
var LFO_index : float = 0.0; 
• Find or create the update() { } function in the same script
• Add the following code to the update() function:
LFO_index = LFO_index + 0.1;
audio.pitch = 1.0 + (Mathf.Sin(LFO_index) * 0.2);
• In the above two lines of code, changing the value of "0.1" will adjust the speed of the LFO modulator
• In the above two lines of code, changing the value of "0.2" will adjust the depth of the LFO modulator
• In the above two lines of code, the audio.pitch attribute can be changed to something else (e.g. audio.volume etc).


0 comments: