Making music play on collision?
Okay, I'm almost completely new to Unity so I'm sorry if this turns out unexpectedly simple and wastes time!
I'm working with a few different music stems which build up together for a full track. I want to make it so that the player runs into a coin, and a track starts playing, runs into another and unlocks another track, builds up etc.
I've set it so all the tracks are muted (except the starter music stem in background), playing on awake (so that they all sync when unmuted) and I'm using the following code:
void OnTriggerEnter2D (Collider2D other) { if (other.gameObject.CompareTag("Collid")) {
GetComponent<AudioSource>().mute = false;
GetComponent<Renderer>().enabled = false;
}
}
(my player is tagged as collid)
It worked fine for the first coin and I got so excited (lol), set the same for all the coins and now its not working. I'm really confused. Did I do something wrong with the code?
Any help would be appreciated so much!!
Your answer
![](https://koobas.hobune.stream/wayback/20220612082302im_/https://answers.unity.com/themes/thub/images/avi.jpg)