How to make a sound only play once whilst still in the air on a jump.
So in my character movement script I'm trying to play the jump audio I have when my character jumps. This works just fine but a problem I have is that: In my game when I hit a enemy object my character movement stops and a menu comes up. The issue here is sometimes I hit a enemy object whilst still in the air. This causes my jump sound to bug out and constantly replay really quickly creating a really awful noise since when i hit the object my character stops moving in the air.
Just to be clear the issue isnt with hitting the actual enemy the problem is that I have the jump sound to play when I jump and since I die on top of the enemy I assume the jump sounds keep repeating itself because I never actually exit the jump because on death all character movement stops so I'm still stuck on top of the hurdle so the jump never really ends and then a menu comes onto the screen.
my current code for the jumping is:
if (controller.isGrounded)
{
// Jumping for pc
verticalVelocity = -gravity * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space))
{
verticalVelocity = jumpForce;
animator.SetBool("is_in_air", true);
jump.Play();
}
}
What would i have to do in here in order to only make the jump.Play(); only play once and not keep repeating itself and making that horrible noise when I die ontop of an enemy object?
Answer by ray2yar · Jan 26, 2019 at 11:11 PM
There should be an option on the clip itself concerning looping... uncheck it.
However, if your problem persists you could mute the audio source.
I do not have the looping on. And on my menu i do have a button to mute all audio sources. a potential way to fix it i guess would be to mute just the jump sound when the death menu pops up.
Your answer
Follow this Question
Related Questions
Trying to get the doors to play the opening and closing sounds seperately/individually 1 Answer
My Player Controllercode isn't working 2 Answers
How to program an AI fighting game code? And how to fix this problem with my Code? 0 Answers
audio script 1 Answer
Play multiple sounds from one object 1 Answer