- Home /
Question by
Trorlroprlro · Oct 07, 2013 at 05:09 PM ·
audiofootsteps
Sprinting Problem
I have a problem. Im trying to create a sprinting script that changes the footstep sound when i press LShift. Also sprinting drains my stamina. Im having a problem when stamina is less than 50 it doesnt play walking sound but it stops all sounds. Help please! Here's my code: var walk:AudioClip; var run:AudioClip; var sta = 1000;
function Update()
{
sta +=1;
if ( ( Input.GetButtonDown( "Horizontal" ) || Input.GetButtonDown( "Vertical" ) ) && !audio.isPlaying ){
audio.clip = walk;
audio.Play();
}
else if ( !Input.GetButton( "Horizontal" ) && !Input.GetButton( "Vertical" ) && audio.isPlaying )
audio.Stop();
if (Input.GetKeyDown("left shift") && sta > 30)
{
Debug.Log("Sprint");
audio.clip = run;
audio.Play();
}
if (Input.GetKeyUp("left shift"))
{
audio.clip = walk;
audio.Play();
}
if (Input.GetKey("left shift") && sta > 30)
{
sta -=2;
}
if(sta < 30)
{
audio.clip = walk;
audio.Play();
}
if(sta > 1000){
sta = 1000;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613115500im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Changing Footstep Sounds On Different Surfaces 0 Answers
footstep audio sync probs 0 Answers
My Footstep isn't working 2 Answers
How do I change footstep sounds on different surfaces? 0 Answers