Je suis actuellement entrain de faire le menu option de mon jeu. Pour le moment je me suis concentré sur les options audio. J'ai fait un GUI slider pour paramétrer cela. J'aimerai pouvoir sauvegarder la valeur du slider et la récupérer lorsque je démarre le jeu. Voici mon script :
Code : Tout sélectionner
if (isOption)
{
GUI.skin = customShip;
GUI.Box(new Rect(DesignWidth / 2 - 700 / 2, DesignHeight / 2 - 500 / 2, 700, 550), "Option");
//menu option
if (!isAudio && !isCommand && !isVideo)
{
GUI.skin = null;
if(GUI.Button(new Rect(DesignWidth / 2 - 150 / 2, DesignHeight / 2 - 200 / 2, 150, 45), "Audio setting"))
{
isAudio = true;
}
if(GUI.Button(new Rect(DesignWidth / 2 - 150 / 2, DesignHeight / 2 - (50) / 2, 150, 45), "Video setting"))
{
isVideo = true;
}
if(GUI.Button(new Rect(DesignWidth / 2 - 150 / 2, DesignHeight / 2 - (-100) / 2, 150, 45), "Command setting"))
{
isCommand = true;
}
GUI.skin = customShip;
if (GUI.Button(new Rect(DesignWidth / 2 - 150 / 2, DesignHeight / 2 - (-250) / 2, 150, 45), "Back"))
{
isOption = false;
}
}
// option audio
if (isAudio)
{
GUI.Label(new Rect(DesignWidth / 2 - 175, DesignHeight / 2 - 135, 300, 300), "Ambience");
GUI.Label(new Rect(DesignWidth / 2 + 115, DesignHeight / 2 - 135, 300, 300), ((int)(ambianceLevel * 100)).ToString() + "%");
ambianceLevel = GUI.HorizontalSlider(new Rect(DesignWidth / 2 - 80, DesignHeight / 2 - 125, 190, 50), ambianceLevel, 0.0f, 1.0f);
PlayerPrefs.SetFloat("Volume", ambianceLevel);
}
if (isVideo)
{
//todo
}
if(isAudio || isVideo || isCommand)
{
if (GUI.Button(new Rect(DesignWidth / 2 - 150 / 2, DesignHeight / 2 - (-250) / 2, 150, 45), "Apply"))
{
if (isAudio)
{
saveSettings();
}
isVideo = false;
isAudio = false;
isCommand = false;
}
}
}