I am trying to make a saving and loading system, I’m using a currentLevel variable’s value to determine the last-saved level. I’m been trying for hours to get it to work and I can’t, here are my scripts.
(New Level Script)
var endOfLevel : Collider;
function OnTriggerEnter (other : Collider) {
currentLevel = 1;
Application.LoadLevel ("Level2");
}
(Save Script)
*After hitting a collider in Level1, I want the currentLevel be set to 1.*
var currentLevel:int;
function Start () {
currentLevel = 0;
}
function LoadSavedLevel () {
if(currentLevel == 0)
{
Application.LoadLevel("Level1");
}
if(currentLevel == 1)
{
Application.LoadLevel("Level2");
}
}
The game will start with currentLevel = 0, which will mean that the game will load the first level once campaign is clicked. However after the first level is “beat” they will go onto the second level along with currentLevel = 1.
(Menu Script)
var buttonWidth:int = 200;
var buttonHeight:int = 50;
var spacing:int = 50;
var menuSkins :GUISkin;
var rolloverSound : AudioClip;
function Start(){
gameObject.GetComponent (TextBox).enabled = false;
}
function OnCollisionEnter () {
audio.PlayOneShot(rolloverSound);
}
function OnGUI()
{
GUI.skin = menuSkins;
GUILayout.BeginArea(Rect(Screen.width/8 - buttonWidth/2, Screen.height/1.4 - 200, buttonWidth, 400));
if(GUILayout.Button("CAMPAIGN", GUILayout.Height(buttonHeight)))
{
LoadSavedLevel();
}
GUILayout.Space(spacing);
if(GUILayout.Button("QUICK MATCH", GUILayout.Height(buttonHeight)))
{
//Nothing Yet
}
GUILayout.Space(spacing);
if(GUILayout.Button("PROFILE", GUILayout.Height(buttonHeight)))
{
gameObject.GetComponent (TextBox).enabled = true;
gameObject.GetComponent (TitleGUI).enabled = false;
}
GUILayout.Space(spacing);
if(GUILayout.Button("OPTIONS", GUILayout.Height(buttonHeight)))
{
gameObject.GetComponent (OptionsMenu).enabled = true;
gameObject.GetComponent (TitleGUI).enabled = false;
}
GUILayout.Space(spacing);
if(GUILayout.Button("EXIT", GUILayout.Height(buttonHeight)))
{
Application.Quit();
}
GUILayout.EndArea();
}
Once the Campaign button is clicked I want it to load the currentLevel = 2 from the save script.
Hopefully the way I explained wasn’t too confusing, any help would be appreciated.