how to make the audio of the other pages stop when i press button?

hi guys,

i make a storybook, and there is button “read to me” and “read by myself”

how do i make it so that when i press the button “read by myself” the audio that i’ve attached to in the other pages dun play?

thanks,
Connie

You need a boolean variable (on or off) and a little bit of coding…

public var play : boolean = true; //Do play the audio automatically
private var isPlaying : boolean = false; //Is the audio already playing?

//vars for GUI!
var buttonwidth : int;
var buttonheight : int;
var xposit1 : int;
var xposit2 : int;
var yposit : int;

function Update() {
   if(play && !isPlaying){
      audio.PlayOneShot("/*name of audio*/");
      isPlaying = true;
}
   else if (!play && isPlaying){
      audio.Stop();
      isPlaying = false;
}
}
function OnGUI(){
   if(GUI.Button(Rect(xposit1,yposit,buttonwidth,buttonheight),"Read to Me")){
      play = true;
}
   if(GUI.Button(Rect(xposit2,yposit,buttonwidth,buttonheight),""Read by Myself)){
      play = false;
}
}