- Home /
audio keeps playing after animation is done
so i have events on my walking and running animation so whenever i hit the ground the sound plays but after i stop walking or running it keeps going , its not on loop to also i tried play one shot , here is my script
public void Step()
{
audiosource.Play();
}
public void Steprun()
{
audiosource.Play();
}
$$anonymous$$ake sure you don't have loop checked in AudioSource my friend.
Answer by Ghazi360 · Dec 10, 2018 at 08:21 PM
Add audioSource.Stop();
its not working it plays and stop immediately i tried before
maybe i placed it somewhere wrong where do i add it ?
Answer by Browntown90 · Dec 12, 2018 at 10:35 PM
The audio is going to continue playing until you stop it. Like @Ghazi360 said, you'd have to add audioSource.Stop();
Since you pointed out that's causing it to stop immediately I'm assuming you've tried something like
public void Step()
{
audioSource.Play();
audioSource.Stop();
}
Which would cause the audio to play and immediately stop. If you want audio to play until you've stopped running, try this, and call Idle() when the animation is set to stop.
public void Step()
{
audioSource.Play();
}
public void Idle()
{
audioSource.Stop();
}
.
so the idle thing do i have to add it somewhere on the editor or something or thats it ?
Answer by Ketoleperouch · Dec 12, 2018 at 10:44 PM
I'm assuming you mean it keeps executing the events that play the sound? If you mean you want to stop the sound, check the other answers.
Are you firing the events within a Blend Tree? Blend Trees execute events even when the 'evented' animation plays for 0.01%, if you know what I mean (so even if e.g. your MoveSpeed parameter inside the Animator is 0.00001, so it plays your Moving animation - with the event - for 0.00001% or so).
You'll want to add a separate boolean that keeps track of whether the sounds should play and edit your script so it behaves correctly, for example:
public void Step() { if (myAnimator.GetBool("Moving")) { audiosource.Play(); } }
etc.
Alternatively, you could use the animator move speed parameter as a variable for the volume of the AudioSource, so the move sound plays at a low volume when you walk slowly, for example:
public void Step() { audiosource.volume = Mathf.Clamp01(myAnimator.GetFloat("MoveSpeed")); audiosource.Play(); }
I hope this is useful to you!
ty so much for your help but am kidna confused am new i dont really know about this but ty for helping , so are both of them different cuz the first one seems easier also if i want to add a new bool what do i do ? i mean how do i reference "$$anonymous$$oving"
Yeah so first of all, are you using events inside the Animation Tracks? If not, then my answers won't help. Both methods are indeed different and to add a new bool you can refer to, you'll have to add one inside the Animator tab inside the Animator window.
Answer by nicholasw1816 · Dec 12, 2018 at 11:53 PM
Make sure the loop is unchecked in the AudioSource Component, in the inspector.
Your answer
Follow this Question
Related Questions
Play from a variety of sounds? 1 Answer
Can I make animations snap to a frame? 1 Answer
stop triggers from retriggering animation 2 Answers
GameObject reacts to audio source 1 Answer
Synchronize Audio and Animation 0 Answers