Good Afternoon,
I am currently attempting to work with music. In my scene, I have a Player and an Empty GameObject with an audio source attached to it. The audio source has the following script attached to it:
function Update() {
if(Input.GetKeyDown(KeyCode.Escape)) {
if(audio.mute)
audio.mute = false;
else
audio.mute = true;
}
}
This script works perfectly, but the opposite way I want it to. The music from the audio source begins to play right when I start the scene and toggles on and off whenever I hit the Escape Key. I need the audio to not start UNTIL I hit the Escape Key and then toggle on and off after that. If anybody could help me out with modifying this script, I would really appreciate!! Thank you so much!!
Btw if you use audio.mute, the song will continue playing even if it's muted. So even if you set audio.mute to true at the beginning, the audio will still start playing, you just won't hear it. If you want to actually pause and continue playing the audio use audio.isPlaying, audio.Play and audio.Pause
– AeonIxion