Platformer Collision Sound Weirdness

Hello everyone. Currently I’m working on a platform game in which the player rolls around as a rock for movement. I’ve stumbled across something strange though in one of my sound effects.

I have a sound effect called RockImpact which essentially is just meant to play when the character hits the ground or a wall. The problem however is that the sound plays way too often.

I discovered that the reason it was playing too often was because of the fact that my ground was made up of several small colliders, which meant the code kept getting run. So I tried getting rid of all of the box colliders and instead covered my ground with one large polygon collider. The sounds still play too frequently however as my character is a circle collider, and being that I have slopes and not all of my edges can be perfectly flat, I’m at a loss for what I should do.

Is there any way I could make this behave a bit better?

Here’s what I’m using, pretty simple and straightforward.

AudioSource rockImpactAudio;

void Start () {

       rockImpactAudio = GetComponent<AudioSource>();

}

void OnCollisionEnter2D (Collision2D collision) {

        if (collision.gameObject.tag == "Ground") {


                rockimpactAudio.Play();   

        }
}

Any help would be very much appreciated!

I would put a timed delay in that just blocks teh sound for playing for a small amount of time…

AudioSource rockImpactAudio;
bool canPlay = true;

void Start () {

       rockImpactAudio = GetComponent<AudioSource>();

}

void OnCollisionEnter2D (Collision2D collision) {

        if (collision.gameObject.tag == "Ground") {
     if(canPlay)
{
                rockimpactAudio.Play();  
canPlay = false;
Invoke("Reset", 0.5f);
}
        }
}

void Reset()
{
  canPlay = true;
}

Any help would be very much appreciated![/QUOTE]