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!!

does audio.mute = true; set the audio to mute? which is what i assume it does.

have you tried setting audio.mute in the start or awake functions?

function Start() {
audio.mute = true;
}

if that doesnt work you could also try

function Update() {

audio.mute = true;

if(Input.GetKeyDown(KeyCode.Escape)) {
if(audio.mute)
audio.mute = false;
else
audio.mute = true;
}
}

Just initialize the mute as true, and then whenever escape is pressed, switch it:

function Start() {
    aduio.mute = true;
}

function Update() {
    if(Input.GetKeyDown(KeyCode.Escape)) {
        audio.mute = !audio.mute;
    }
}