I am trying to build a script that would save the last scene you were on but it looks like it doesn’t work by any means.By saving the last scene i mean saving the progress and sending you to Map Scene which is like a mainmenu So i have a principal Map scene where you have to press on one specific collider to send you to a Map1,2,3 etc. So the game logic would look like this if press on collider for the first time - sends you to map1 In map1 if you kill all the zombies - sends you to Map If press on collider again- sends you to map2 In map2 if you kill all the zombies - sends you to Map And so on… I attached a script to my Map Scene which is not working
using UnityEngine;
using System.Collections;
public class DWP : MonoBehaviour {
public static int zombiesdeaths;
//private bool data = true;
//private bool stergeKey = false;
void Awake()
{
if(!PlayerPrefs.HasKey ("CurentMap"))
{
PlayerPrefs.SetInt ("CurentMap", 1);
}
zombiesdeaths = 9;
Debug.Log ("Awake");
//if(stergeKey == true)
// PlayerPrefs.DeleteAll ();
}
void OnMouseDown()
{
Debug.Log ("CLICK-UL MASII");
StartCoroutine ("Downwoods");
animation.Play ("testtouch");
}
IEnumerator Downwoods()
{
yield return new WaitForSeconds (2);
if(PlayerPrefs.GetInt("CurentMap")==1)
{
zombiesdeaths=9;
}
if(PlayerPrefs.GetInt("CurentMap")==2)
{
zombiesdeaths=9;
}
if(PlayerPrefs.GetInt("CurentMap")==3)
{
zombiesdeaths=9;
}
print ("ienumerator");
Application.LoadLevel("Map"+PlayerPrefs.GetInt("CurentMap").ToString());
}
}
And the Map1,Map2,Map3 Script function is the following:
void Kill ()
{
DWP.zombiesdeaths--;
Debug.Log (DWP.zombiesdeaths );
if(DWP.zombiesdeaths<1)
{
//Time.timeScale = 0;
Debug.Log("ADIO");
PlayerPrefs.SetInt("CurentMap",PlayerPrefs.GetInt("CurentMap")+1);
Application.LoadLevel("MapScene");
}
Destroy( gameObject );
}