I want to have three buttons that each when selected change the current audio track to track one, track two, and track three respectively. To do this, I defined a var for each of the audio sources along with defining an integer called SelectedTrack in order to make it so by clicking on a button the integer would be set to a value of 1,2, or 3 and that if SelectedTrack=1 then track one would play and so on for track two and three.
This is the code that I have right now for my GUI setup:
var PauseWallpaper : GUISkin;
var TrackOne : AudioSource;
var TrackTwo : AudioSource;
var TrackThree : AudioSource;
var SelectedTrack : Int = 1;
static var ToggleMenu : boolean = false;
function Update()
{
if(Input.GetKeyDown(KeyCode.Escape)){
GetComponent("MouseLook").enabled = !GetComponent("MouseLook").enabled;
GetComponent("Camera").enabled = !GetComponent("Camera").enabled;
PauseGame();
}
if(SelectedTrack=1){
audio.Play(TrackOne);
}
if(SelctedTrack=2){
audio.Play(TrackTwo);
}
if(SelctedTrack=3){
audio.Play(TrackThree);
}
}
static function PauseGame()
{
if(!ToggleMenu)
{
Time.timeScale=0;
AudioListener.pause = true;
ToggleMenu=true;
}
else
{
Time.timeScale=1;
AudioListener.pause = false;
ToggleMenu=false;
}
}
function OnGUI()
{
if(GUI.Button(Rect(0,0,100,50),"Track One")){
SelectedTrack = 1;
}
if(GUI.Button(Rect(0,0,100,50),"Track Two")){
SelectedTrack = 2;
}
if(GUI.Button(Rect(0,0,100,50),"Track Three")){
SelectedTrack = 3;
}
if(ToggleMenu) //if ToggleMenu = true execute follwing.
{
GUI.skin = PauseWallpaper;
GUI.Box(Rect (0,0,Screen.width,Screen.height), "PAUSED");
if(GUI.Button(Rect (Screen.width / 2 - 50, Screen.height / 2 - 75, 100, 50), "Exit Program")){
Application.Quit();
}
if(GUI.Button(Rect (Screen.width / 2 - 50, Screen.height / 2 - 25, 100, 50), "Level Select")){
//script
}
}
}
These are the errors that currently come up : (14,25): BCE0044: expecting ), found '='. (14,26): BCE0043: Unexpected token: 1. (15,29): BCE0044: expecting :, found ';'.
Lines 43 to 51 is where I want to change the integer value when each button is pressed. and 14 to 22 is where I want the current track playing to be based off of the integer value.
Any help figuring this out is greatly appreciated.