Running sounds repeat too often?
Obviously the sounds are being called every frame so even if you put a delay in between the different stepping sounds you'll be hearing those sounds 60 times per second whenever you hit the key that moves the character forward. Maybe I'm stupid but how would you prevent that, even if you made a bool true whenever the character is running and then made that trigger a coroutine wouldn't the code keep running every frame. Maybe I'm just confused, anyone care to set my mind straight. :)
StartCoroutine("RunningSounds");
IEnumerator RunningSounds()
{
yield return new WaitForSeconds(0.5f);
walk1.Play();
yield return new WaitForSeconds(0.5f);
walk2.Play();
yield return new WaitForSeconds(0.5f);
}
Answer by Haugkall · Mar 16, 2018 at 05:01 PM
I think I get the problem, you shouldn't trigger the sounds when you hit the forward key but when the character is moving. So you have to check for if it's moving or not. I'm not quite sure how to do that. Here is how he is currently moving and under that is the if statement I need to modify to check if he's moving or not. Anyone know what I'm suppose to look for?
//Player movement.
float vertical = Input.GetAxis("Vertical");
if (vertical > 0)
{
anim.SetBool("isRunning", true);
vertical = characterFSpeed;
}
else
{
anim.SetBool("isRunning", false);
}
if (vertical < 0)
{
vertical = -characterBSpeed;
}
playerTransform.Translate(0, 0, vertical * Time.deltaTime);
if(touchesGround == true && playerTransform.transform. > 0.5f && walk1.isPlaying == false && walk2.isPlaying == false)
{
StartCoroutine("RunningSounds");
}
Your answer
Follow this Question
Related Questions
Mono Debugger - line by line stepping? 0 Answers
I have to start moving first to run, and cant start moving in the other direction when running. 0 Answers
Animator & Sounds 0 Answers
running infinite 2 Answers