OnTriggerEnter2D --> One Shot Audio Problem

All I’m trying to do is play a sound and disable the sprite when the character runs into it.

So far the code below will play the sound and disable the sprite on TriggerEnter, but the problem is I can run over the trigger again (with the sprite disabled) and the sound will play again. I attempted to stop the sound from playing when the sprite is disabled, but I can’t figure it out.

	public AudioClip coinHit;
	
    
	void OnTriggerEnter2D(Collider2D mario) {

		if (renderer.enabled = true) {

						audio.PlayOneShot (coinHit);
			
						renderer.enabled = false;

						Debug.Log ("The sprite was on.");

				} 

		if (renderer.enabled = false) {

						Debug.Log ("The sprite was off.");

				}
	
	}



}

When you disable your sprite, you also have to disable the collider… Then it won’t be active anymore so it won’t detect the interaction and won’t play the sound again.

renderer.enabled = false;
collider2D.enabled = false; // add this here.

I hope it helps.