The scenes simply dont change
Here is my code:
using UnityEngine;
using System.Collections;
public class LevelController : MonoBehaviour {
public static LevelController instance;
public int xpMultiply = 1;
public float xpFirstLevel = 100;
public float difficultyFactor = 1.5f;
// Use this for initialization
void Start () {
Application.LoadLevel ("1");
instance = this;
DontDestroyOnLoad (gameObject);
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.A))
AddXp (100);
if (Input.GetKeyDown (KeyCode.R))
PlayerPrefs.DeleteAll();
}
public static float GetCurrentXp() {
return PlayerPrefs.GetFloat ("currentXp");
}
public static void AddXp(float xpAdd) {
float newXp = (GetCurrentXp() + xpAdd)*LevelController.instance.xpMultiply;
if (newXp >= GetNextXp()) {
AddLevel ();
newXp = 0;
}
PlayerPrefs.SetFloat ("currentXp", newXp);
}
public static int GetCurrentLevel() {
return PlayerPrefs.GetInt ("currentLevel");
}
public static void AddLevel() {
int newLevel = GetCurrentLevel() + 1;
PlayerPrefs.SetInt ("currentLevel", newLevel);
}
void OnGUI(){
GUI.Label (new Rect(0, 0, 200, 50), "Current XP = " + GetCurrentXp());
GUI.Label (new Rect(0, 70, 200, 50), "Current XP = " + GetCurrentLevel());
GUI.Label (new Rect(0, 140, 200, 50), "Current Next Xp = " + GetNextXp());
}
public static float GetNextXp() {
return LevelController.instance.xpFirstLevel * GetCurrentLevel()+1 * LevelController.instance.difficultyFactor;;
}
}
`
`