How to make dynamic sounds for rolling ball?

I’m creating a game where your character is a ball.
You control the ball by accelerating left and right, but I’m coming to a point where I would like to add some audio to the project.

I was wondering if anyone had experience with dynamically changing sounds.
This is what I really need to know:

  • What kind of sound should I use (short looping sound or long loop?)
  • How can I make the sound variable according to the speed of the ball

Thanks for your help!

The easiest way I can think of to dynamically change the properties of the sound would be to change the properties of the audio source (see: http://unity3d.com/support/documentation/ScriptReference/AudioSource.html).

You could have variables created for the pitch and volume and then change those variables based on changes in the ball movement. With looping audio playing from an audio source on the ball, the sound would be changed accordingly.

Something like this:

var ballSpeed:float;
var volume:float;
var pitch:float;
var k:float = 0.1; //constant for pitch calculation
var c:float = 0.5; //constant for volume calculation

function Update() {

pitch = ballSpeed * k;
volume = ballSpeed * c;
audio.pitch = pitch;
audio.volume = volume;

}