- Home /
Gui Playing Audio Trouble
Hello, Im currently attempting to make a script so when i click a gui button then a list of songs appear. And if i click one of those songs i want it to play it. But its not working the way i want it to. Here is my script.
var Song1 : AudioClip; var Song1WasPressed = false; var showMoreGui = false;
function OnGUI () {
if (GUI.Button (Rect (10,10,100,20), "Show More"))
{ showMoreGui = true;
}
if (showMoreGui) {
if(GUI.Button (Rect (10, 40,100,20), "Song1")); { Song1WasPressed = true; }
if (GUI.Button (Rect (10, 70,100,20), "Close"))
{ showMoreGui = false;
}
} }
function Update() { if(Song1WasPressed) { audio.clip = Song1; audio.Play(); } }
Thanks for any help!!
Answer by Adam Rademacher · Nov 11, 2010 at 11:27 PM
I think your issue is that it's re-setting the audio every update. Try this in your update function:
if(Song1WasPressed)
{
audio.clip = Song1;
audio.Play();
Song1WasPressed = false;
}
i guess that just slipped my $$anonymous$$d to make the variable false again so it wouldnt try playing the audio every frame.Thank-You very much.