- Home /
how to make an sliding sound effect?
I have my character slide along a wall kind of like in megaman X and I want it to make an sliding sound effect, the problem is that I can't make it sound right, this is the code I'm using:
public AudioClip resbaladizo;
void Awake()
{
audio.clip = resbaladizo;
}
void OnCollisionStay (Collision lacolision) {
if(lacolision.gameObject.tag == "Player" && (lacolision.rigidbody.velocity.y<-5 || lacolision.rigidbody.velocity.y>5))
{
audio.Play();
}}
As expected, the sound clip sounds every frame the character is in the wall so the one-second sliding sound effect sounds terrible as it is being re-played every frame. Anybody has a good solution for this? Thanks in advance!
try putting a check that if it's playing to not start playing it again and see how it sounds.
Answer by Ekta-Mehta-D · Aug 22, 2014 at 07:36 AM
Hello..
Check your sound setting loop is false and play on awake is true.
or else you can try this :
public boolean soundOnce = true;
void OnCollisionEnter(Collision collision) {
if(soundOnce)
{
audio.Play();
soundOnce = false;
}
}
void OnCollisionExit(Collision collisionInfo) {
soundOnce = true;
}
Thanks.
Answer by el-RERS · Aug 22, 2014 at 04:47 PM
Thanks everyone. I actually solved the problem by using audio.isplaying in my condition and audio.stop in On CollisionExit. It kinda works now, thanks again!
Your answer
Follow this Question
Related Questions
Unity plays only a few gameobject's sound 2 Answers
How to play multiple audio files from one script 1 Answer
AudioClip calculates length wrong 1 Answer
Sound play in spot of particle collision 1 Answer
Roll A Ball Sound 1 Answer