I am trying to create a js script that plays a random footstep sound when I'm on a particular surface, like gravel or metal, but everything I try doesn't work. I have searched the forums and not found anything.
This is what I have already got.
var WalkSoundInterval:float = 0.5;
var FootstepsVolume:float = 0.5;
var FootstepSoundsNormal:AudioClip[];
var FootstepSoundsGravel:AudioClip[];
var FootstepSoundMetal:AudioClip[];
InvokeRepeating("UpdateInterval",0,WalkSoundInterval);
function UpdateInterval()
{
if(Input.GetKey("w"))
{
audio.clip = FootstepSoundsNormal[Random.Range(0,FootstepSoundsNormal.length)];
audio.volume = FootstepsVolume;
audio.PlayOneShot(audio.clip);
}
}
I have tried using the OnCollisionEnter to switch a boolean to true, but that didn't work and nothing else I try works. Please help.
Thanks in advance.
↧