Blink
1
I have animations on my camera to give the effect of walking, on these animations I have triggers to tell a script when to play a footstep sound. This all works fine but I only have one footstep sound that gets played, I have three different sounds that I would like to be played randomly but I dont know how I would do this. This is my script can anyone help me out?
var footsteps : AudioClip;
function footstepsEvent(){
var footstepsEvent = new AnimationEvent();
footstepsEvent.functionName = "footstepsSound";
footstepsEvent.time = 0.0;
animation["gun walk"].layer = 1;
animation["gun walk"].clip.AddEvent(footstepsEvent); // Add the event to an AnimationClip
animation["gun walk"].wrapMode = WrapMode.Once;
animation.Play("gun walk");
}
function footstepsSound(){
audio.volume = 0.1;
audio.clip = footsteps;
audio.Play();
}
var footsteps : AudioClip;
function footstepsEvent(){
var footstepsEvent = new AnimationEvent();
footstepsEvent.functionName = "footstepsSound";
footstepsEvent.time = 0.0;
animation["gun walk"].layer = 1;
animation["gun walk"].clip.AddEvent(footstepsEvent); // Add the event to an AnimationClip
animation["gun walk"].wrapMode = WrapMode.Once;
animation.Play("gun walk");
}
function footstepsSound(){
audio.volume = 0.1;
audio.clip = footsteps[Random.Range(0, footsteps.length)];
audio.Play();
}
If I’m not mistaken that should do it.
Turn the footsteps variable into an Array, from which you select one randomly and then you play it.