I have a menu with a slider set up so I can adjust the volume. Although it works for my volume screen scene, it doesn’t work in any other scene. I think I need to store the hsliderValue but I’m not even sure TBH. would really appreciate an assist.
var backButton : Texture2D;
var backRollover : Texture2D;
var mouseEnterSound : AudioClip;
var mouseExitSound : AudioClip;
var hSliderValue : float = 0.5;
private var correctedMousePosition : Vector2;
private var mouseOver = false; // current mouse status
private var isOver = false; // used to check status change
function CheckButton(r: Rect, texOver: Texture2D, texOut: Texture2D): boolean {
if ( r.Contains(correctedMousePosition) ) // if mouse over the button...
{
GUI.DrawTexture( r, texOver ); // draw the over texture...
isOver = true; // set isOver flag...
return Input.GetMouseButtonUp(0); // and return mouse up status
}
else
{
GUI.DrawTexture( r, texOut ); // otherwise draw regular texture...
return false; // and return false
}
}
function OnGUI ()
{
correctedMousePosition = Vector2 (Input.mousePosition.x, (Screen.height-Input.mousePosition.y) );
isOver = false; // prepare mouse enter/exit detection
hSliderValue = GUI.HorizontalSlider(Rect(300,180,200,20), hSliderValue, 0.0, 1.0);
GUI.Label(Rect(300,195,200,20), "Music="+hSliderValue);
audio.volume = hSliderValue;
if ( CheckButton( Rect(250,250,200,50), backRollover, backButton) )
{
Application.LoadLevel(1);
}
if (isOver != mouseOver){ // if mouse entered or exited button...
mouseOver = isOver; // update mouseOver and play appropriate sound
if (mouseOver){
audio.PlayOneShot(mouseEnterSound);
} else {
audio.PlayOneShot(mouseExitSound);
}
}
}