i want to save audio options editing

f (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+58 , 150 , 50), “Back” ))
{
PlayerPrefs.SetFloat(“Musicone”,audio.volume) ;

options = true ;
soundquality = false ;
audio.PlayOneShot(sound) ;
}

this to save the changes in slider bar for music volume

if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2-48 , 150 , 50), “Play” ))
{
PlayerPrefs.GetFloat(“Musicone”,audio.volume) ;
audio.PlayOneShot(sound) ;
Application.LoadLevel(“MainMenuScene”) ;

}

and this for loading when i press play to load he same volume values if i go to another scene

but it is not working
? !!!

Please use Code Tags when posting code on the forums.

1 Like

ok
this for saving the editing

#pragma strict
var optionssound  : GameObject ;
function Start () {

}

function Update () {

audio.volume = optionssound.GetComponent(MainMenuButton).soundeffect ;
audio.volume = optionssound.GetComponent(MainMenuButton).soundmusic ;

if (audio.volume == optionssound.GetComponent(MainMenuButton).soundeffect )
{
PlayerPrefs.SetFloat("Musicone",audio.volume ) ;

}
if (audio.volume ==  optionssound.GetComponent(MainMenuButton).soundmusic )
{


PlayerPrefs.SetFloat("Musicone",audio.volume ) ;


}

and this for load the editing 
[code=JavaScript]
if ( soundquality )
{
soundeffect = GUI.HorizontalSlider (Rect(Screen.width/2-50 , Screen.height/2 , 100,30 ) , soundeffect , 0.0  , 1.0 ) ;
GUI.Label(Rect(Screen.width / 2 -100 , Screen.height/2  , 100 , 30 ) , "SFX: " +( soundeffect * 10 ).ToString("f0") ) ;

soundmusic = GUI.HorizontalSlider (Rect(Screen.width/2-50 , Screen.height/2 - 50 , 100,30 ) , soundmusic , 0.0  , 1.0 ) ;
GUI.Label(Rect(Screen.width / 2 - 100 , Screen.height/2 - 50 , 100 , 30 ) , "Music: " + (soundmusic *  10 ).ToString("f0") ) ;


if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+58 , 150 , 50), "Back" ))
{
PlayerPrefs.SetFloat("Musicone",audio.volume) ;

options = true ;
soundquality = false ;
audio.PlayOneShot(sound) ;
}



}

}[/code]

the full Scripts

this for saving

#pragma strict
var optionssound  : GameObject ;
function Start () {

}

function Update () {

audio.volume = optionssound.GetComponent(MainMenuButton).soundeffect ;
audio.volume = optionssound.GetComponent(MainMenuButton).soundmusic ;

if (audio.volume == optionssound.GetComponent(MainMenuButton).soundeffect )
{
PlayerPrefs.SetFloat("Musicone",audio.volume ) ;

}
if (audio.volume ==  optionssound.GetComponent(MainMenuButton).soundmusic )
{


PlayerPrefs.SetFloat("Musicone",audio.volume ) ;


}




}

and this For loading it when go to another scene

#pragma strict
//var ButtonSyle : GUIStyle ;
var sound : AudioClip  ;  // audio music
var menu  : boolean ;  // menu boolean
var options :boolean  ; // options boolean
var soundquality : boolean  ;  //
var video : boolean ;

var soundeffect : float = 6 ;
var soundmusic : float = 6 ;
var fieldofview : int = 80  ;
var maincam : Camera ;
function Start () {
menu = true ;
options = false ;
soundquality = false ;
video = false ;
}

function Update () {

}
function OnGUI ()
{
if ( menu)
{


GUI.Box(Rect(Screen.width/2-75, Screen.height/2-50,200,245 ),"" ) ;
if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2-48 , 150 , 50), "Play" ))
{
PlayerPrefs.GetFloat("Musicone",audio.volume) ;
audio.PlayOneShot(sound) ;
Application.LoadLevel("MainMenuScene") ;




}


if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+5 , 150 , 50), "How To Play" ))
{
audio.PlayOneShot(sound) ;
Application.LoadLevel("Tutorial scene") ;
}

if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+58 , 150 , 50), "Rate Us" ))
{
audio.PlayOneShot(sound) ;
Application.OpenURL ("https://play.google.com/store/apps/details?id=com.gobla.lastline") ;
}

if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+111 , 150 , 50), "Options" ))
{
menu = false ;
options = true ;
audio.PlayOneShot(sound) ;
}


if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+164, 150 , 50), "Quit" ))
{
audio.PlayOneShot(sound) ;
Application.Quit () ; 
}
}










/////////////////////////////////////////////////////////////////////////////////////////////////////


if ( options )
{
if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2-48 , 150 , 50), "Audio Settings" ))
{

soundquality = true ;
options = false ;
audio.PlayOneShot(sound) ;
}
if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+5 , 150 , 50), "Video Settings" ))
{
soundquality = false ;
video = true ;
options = false ;
audio.PlayOneShot(sound) ;
}

if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+58 , 150 , 50), "Back" ))
{
menu = true ;
options = false ;
audio.PlayOneShot(sound) ;
}




}
















if ( soundquality )
{
soundeffect = GUI.HorizontalSlider (Rect(Screen.width/2-50 , Screen.height/2 , 100,30 ) , soundeffect , 0.0  , 1.0 ) ;
GUI.Label(Rect(Screen.width / 2 -100 , Screen.height/2  , 100 , 30 ) , "SFX: " +( soundeffect * 10 ).ToString("f0") ) ;

soundmusic = GUI.HorizontalSlider (Rect(Screen.width/2-50 , Screen.height/2 - 50 , 100,30 ) , soundmusic , 0.0  , 1.0 ) ;
GUI.Label(Rect(Screen.width / 2 - 100 , Screen.height/2 - 50 , 100 , 30 ) , "Music: " + (soundmusic *  10 ).ToString("f0") ) ;


if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+58 , 150 , 50), "Back" ))
{
PlayerPrefs.SetFloat("Musicone",audio.volume) ;

options = true ;
soundquality = false ;
audio.PlayOneShot(sound) ;
}



}










if ( video )
{
var qualitties = QualitySettings.names ;
GUILayout.BeginVertical () ;

for ( var i = 0 ; i < qualitties.length ; i++ )
{
if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+58+i *30 , 150 , 50),qualitties[i])) 
{
QualitySettings.SetQualityLevel(i , true ) ;
options = true ;
soundquality = false ;
audio.PlayOneShot(sound) ;
}





}
GUILayout.EndVertical () ;

fieldofview = GUI.HorizontalSlider (Rect(Screen.width/2-50 , Screen.height/2 , 100,30 ) , fieldofview , 30  , 120 ) ;

maincam.fieldOfView = fieldofview ;
GUI.Label(Rect(Screen.width / 2 - 50 , Screen.height/2 - 5 , 100 , 30 ) , "FOV: " + fieldofview ) ;


if (GUI.Button(Rect(Screen.width/2-50, Screen.height/2+58 , 150 , 50), "Back" ))
{
options = true ;
soundquality = false ;
audio.PlayOneShot(sound) ;


















}

}

}

and this for

؟؟؟؟؟؟؟؟؟؟؟