Sound question

I have a simple script that can set the sound on or off. Or i have two questions. This is the script:

var sound : boolean = false;
var music : AudioClip;
function OnGUI () {
	GUI.Box (Rect (10,10,120,90), "Options");
	if (GUI.Button (Rect (20,40,100,20), "Sound on/off")) {
		if(sound) {
		sound=false;
		}
		else {
		sound = true;
		
		}
	}
}

First if the sound is true, then wil i that music begins play. I wil that he loop, so long i click not on the button. Or if the sound is false, then wil i that the music stops. Can anyone help me?

NOTE:i am a script noob.

The reference is your friend: AudioSource :slight_smile:

An AudioClip contains audio, and an AudioSource can play that audio. So create an AudioSource and assign your AudioClip to its clip property. Then you can call Play(), Stop(), Pause() or PlayOneShot() on you AudioSource to control playback of the clip from your code.

AudioSources also have a loop property that you can toggle in the inspector window, or through code.