- Home /
Play sound while moving.
I am looking for a script to loop a sound while the player is moving. I can't have the sound just play while the player is holding down a movement key, because of the sliding mechanic that I have. Is there a way to loop the sound while the acceleration is greater than 0? Also a script to not play the sound while not on the ground would be helpful.
Thank you! :D
Answer by BPR · Apr 21, 2013 at 08:34 AM
Hi, try something like this:
if(grounded && acceleration < 0 ){
if(!audio.isPlaying()){
audio.clip = yourclip;
audio.Play();
}
}
now you have to find a way to determine whether you are touching the ground and set the grounded bool accordingly, for example check whether your collider intersects with a collider of an object with tag "Ground" etc.
Regards BPR
Answer by xolan007 · Apr 21, 2013 at 09:24 AM
if(rigidbody.velocity.magnitude >= 0.2)
{
//Play sound here if you have a rigidbody component and if your movement is rigidbody.AddForce
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Audio Destroy Help! 1 Answer
Can anyone help me invert this simple script? 2 Answers
Stuck on this! Please help me out. 1 Answer
Wait for sound is played 2 Answers