I've looked through most of the similar questions here, and tried different variations of my code, but I'm still unable to get it to work right.
Just to make it clear, I want a sound to be heard when I click my button before it loads to a level.
The code I'm currently using is:
var start : GUIStyle;
var quite : GUIStyle;
var instruction : GUIStyle;
var history : GUIStyle;
var mySound : AudioClip;
function OnGUI ()
{
if(GUI.Button (Rect(800,260,250,160),"",start))
{
audio.Play();
if (!audio.isPlaying)
{
Application.LoadLevel ("Proj");
}
}
if(GUI.Button (Rect(250,600,240,130),"",quite))
{
audio.Play();
if (!audio.isPlaying)
{
Application.Quit ();
}
}
if(GUI.Button (Rect(790,520,250,130),"",instruction))
{
audio.Play();
if (!audio.isPlaying)
{
Application.LoadLevel ("instruction");
}
}
if(GUI.Button (Rect(240,270,290,140),"",history))
{
audio.Play();
if (!audio.isPlaying)
{
Application.LoadLevel ("History");
}
}
}
This only allows an audio clip to be played upon clicking the button, but it doesn't load the respective levels. When I use this code:
if(GUI.Button (Rect(800,260,250,160),"",start))
{
audio.Play();
Application.LoadLevel ("Proj");
}
if(GUI.Button (Rect(250,600,240,130),"",quite))
{
audio.Play();
Application.Quit ();
}
if(GUI.Button (Rect(790,520,250,130),"",instruction))
{
audio.Play();
Application.LoadLevel ("instruction");
}
if(GUI.Button (Rect(240,270,290,140),"",history))
{
audio.Play();
Application.LoadLevel ("History");
The levels are loaded, but the audio clips are not played. Can anyone tell me where I went wrong?
Thank you!