Hey guys, i need your help for a code, i have my script for FootSteps sound, works great, but i have a little issue, when i jump and walk at the same time, the sound don’t stop, i need it to play only the on ground, can you guys help me?
#pragma strict
//Set your variable for the footstep audioclips
var footstepsWood : AudioClip;
var footstepsMetal : AudioClip;
var footstepsStone : AudioClip;
var character : CharacterController;
//This script requires that an audio source component is attached to your First Person Controller
@script RequireComponent(AudioSource);
function Awake(){
character = GetComponent(CharacterController);
}
function LateUpdate ()
{
//Check whether the user is moving the player
if(character.isGrounded){
if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal"))
{
// if the audio is not playing then play - this stops it playing multiple clips at thye same time
if (!audio.isPlaying)
{
audio.Play();
}
}
else
{
audio.Stop();
}
}
}
function OnControllerColliderHit (hit : ControllerColliderHit)
{
// if your character controller is on a floor piece tagged as woodFloor then it sets the audioClip as footstepsWood and sets the volume to 90%
if (hit.gameObject.tag == "woodFloor")
{
audio.clip = footstepsWood;
audio.volume = 1.0;
}
else if (hit.gameObject.tag == "metalFloor")
{
audio.clip = footstepsMetal;
audio.volume = 1.0;
}
else if (hit.gameObject.tag == "stoneFloor")
{
audio.clip = footstepsStone;
audio.volume = 1.0;
}
}