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.");
}
}
}