- Home /
Question by
smirlianos · Oct 04, 2012 at 09:13 AM ·
javascriptsoundbeginnerjavamusic
Play and stop sound
Hi, I'm new to unity, how can i make footsteps play while my character walk? I have this script, but it doesn't work. Please help?
function Update () { if(Input.GetButton("Horizontal") || Input.GetButton("Vertical")) { audio.Play(); } }
Comment
Someone help??? I ment hear footsteps, not make ones...
Best Answer
Answer by Griffo · Oct 04, 2012 at 11:14 AM
Something like this ..
#pragma strict
var WalkingSound : AudioClip;
function Update ()
{
if(Input.GetButton("Horizontal") || Input.GetButton("Vertical"))
{
PlayerWalkSound();
}
}
function PlayerWalkSound(){
audio.volume = 0.5;
if (!audio.isPlaying){
audio.clip = WalkingSound;
audio.pitch = Random.Range(0.8f, 1.0f);
audio.Play();
}
}