In my pause menu I have a series of button but i want to add a save button to it that will save everything so i dont keep losing everything but I have no idea how to do this.
I have included my script below, any idea how to do this anyone ???
var skin:GUISkin;
private var gldepth = -0.5;
private var startTime = 0.1;
private var savedTimeScale:float;
private var pauseFilter;
var mainObjective:String[]=[
"- Get to room 8 for English lesson",
"- When the fire alarm goes off,",
" make your way to the playground in the time"];
var subObjective:String[]=[
"Collect 10 Keys",
"Make first steps"];
enum Page {
None,Main,Options,Objective,MainMenu
}
private var currentPage:Page;
function Start() {
Time.timeScale = 1.0;
PauseGame();
}
function LateUpdate () {
if (Input.GetKeyDown("escape")) {
switch (currentPage) {
case Page.None: PauseGame(); break;
case Page.Main: if (!IsBeginning()) UnPauseGame(); break;
default: currentPage = Page.Main;
}
}
}
function OnGUI () {
if (skin != null) {
GUI.skin = skin;
}
if (IsGamePaused()) {
switch (currentPage) {
case Page.Main: PauseMenu(); break;
case Page.Options: ShowToolbar(); break;
case Page.Objective: ObjectiveToolbar(); break;
case Page.MainMenu: OpenLevel("MainMenu"); break;
}
}
}
private var toolbarInt:int=0;
private var toolbarStrings: String[]= ["Audio","Graphics"];
private var obToolbarStrings: String[]= ["Main Objective","Sub Objective"];
function ShowToolbar() {
BeginPage(400,300);
toolbarInt = GUILayout.Toolbar (toolbarInt, toolbarStrings);
switch (toolbarInt) {
case 0: VolumeControl(); break;
case 1: Qualities(); QualityControl(); break;
}
EndPage();
}
function ObjectiveToolbar() {
BeginPage(400,300);
toolbarInt = GUILayout.Toolbar (toolbarInt, obToolbarStrings);
switch (toolbarInt) {
case 0: MainObjective(); break;
case 1: SubObjective(); break;
}
EndPage();
}
function MainObjective() {
for (var credit in mainObjective){
GUILayout.Label(credit);
}
}
function SubObjective() {
for (var cred in subObjective){
GUILayout.Label(cred);
}
}
function ShowBackButton() {
if (GUI.Button(Rect(20,Screen.height-50,70,20),"Back")) {
currentPage = Page.Main;
}
}
function Qualities() {
GUILayout.Label(QualitySettings.names[QualitySettings.GetQualityLevel()]);
}
function QualityControl() {
GUILayout.BeginHorizontal();
if (GUILayout.Button("Decrease")) {
QualitySettings.DecreaseLevel();
}
if (GUILayout.Button("Increase")) {
QualitySettings.IncreaseLevel();
}
GUILayout.EndHorizontal();
}
function VolumeControl() {
GUILayout.Label("Volume");
AudioListener.volume = GUILayout.HorizontalSlider(AudioListener.volume,0.0,1.0);
}
function BeginPage(width,height) {
GUILayout.BeginArea(Rect((Screen.width-width)/2,(Screen.height-height)/2,width,height));
}
function EndPage() {
GUILayout.EndArea();
if (currentPage != Page.Main) {
ShowBackButton();
}
}
function IsBeginning() {
return Time.time < startTime;
}
function PauseMenu() {
BeginPage(200,200);
if (GUILayout.Button (IsBeginning() ? "Play" : "Continue")) {
UnPauseGame();
}
if (GUILayout.Button ("Options")) {
currentPage = Page.Options;
}
if (GUILayout.Button ("Objective")) {
currentPage = Page.Objective;
}
if (GUILayout.Button ("Main Menu")) {
currentPage = Page.MainMenu;
}
EndPage();
}
function PauseGame() {
savedTimeScale = Time.timeScale;
Time.timeScale = 0;
AudioListener.pause = true;
if (pauseFilter) pauseFilter.enabled = true;
currentPage = Page.Main;
}
function UnPauseGame() {
Time.timeScale = savedTimeScale;
AudioListener.pause = false;
if (pauseFilter) pauseFilter.enabled = false;
currentPage = Page.None;
}
function IsGamePaused() {
return Time.timeScale==0;
}
function OnApplicationPause(pause:boolean) {
if (IsGamePaused()) {
AudioListener.pause = true;
}
}
function OpenLevel(level : String){
Application.LoadLevel(level);
UnPauseGame();
}