Hey,
I’m new to Unity and these forums (though not C#), and though I prefer to try find the answer myself, I’m truly stuck on this one.
Background I’m carrying on from the Space Shooter project, adding features to get some practice and it’s all going very well (I have the code up on github if anyone is interested).
Problem I’m trying to create a powerup ability - nothing fancy, 3 bolts instead of 1 fire. And I want the music to change once the powerup is activated - very simple. However, no matter what I do, when the music is supposed to come on, I hear “silence” - it’s actually this weird fluttering sound. Like bats or something tapping the “mic”.
I’ve tried a few different methods but the gist is:
-
I have an AudioSource w/ background music clip attached to GameController. Music plays fine in all circumstances.
-
I have an AudioSource/ with newBackground music clip attached to a gameObject. If this is set as the initial background music, everything works perfectly. The problem occurs when the music is supposed to switch.
I’ve tried:
backgroundmusic.Audio.Stop();
newBackgroundmusic.Audio.Play();
=> Weird fluttering
Destroy(backgroundmusic);
newBackgroundmusic.Audio.Play();
=> Weird fluttering
Thinking that because my triggering of the sound files depends on the Update() function (at the moment, getting a score of 10 triggers it as a test), that perhaps it needs time to clear up any used objects before it can be reused… Or something. Nope, I added a function to wait several seconds to test that. I’ve tried it as an *.mp3 and *.wav file. Also, that doesn’t make sense since they both play fine simultaneously - if I set them both to Play On Awake, it works completely fine.
Finally, one weird thing. Sometimes the music actually does trigger! But at only weird times. Like after you’ve triggered the powerup, then died to trigger the gameOver event and then it might play. Other times I hear it starting the moment I end the game (in Unity that is).
Which makes me think that it’s related somehow to an object being “tied up” with some other process. Incidentally, I tried storing the AudioSources in an array but I was having problems with that as well. One of my sound effects for the enemy ship exploding magically disappeared a few days ago so perhaps it’s related…
So that’s the gist of things… I’m not new to programming but I’m far from an expert, and I’m lost… If anyone could recommend a function/site/etc I’m sure I can figure out the rest… Thanks guys!