I wanted to use function OnMouseDown(){} to load the last level that was open, and I cant find anywhere that shows how to do that? Can someone help? Thanks in advance…
EDIT:
I have this script for loading last played level on awake, but i cant figure out the script to attach to a box collider that I want to click to load the last level:
//LevelLoadManager.js
private var currentLevel:int = -1;
function Awake():void
{
//retrieve and load last level played.
DontDestroyOnLoad(gameObject);
currentLevel = PlayerPrefs.GetInt("LastLevelLoaded");
Application.LoadLevel(currentLevel);
}
function Update():void
{
//save the current level if it seems to have changed.
if(Application.loadedLevel != currentLevel)
{
currentLevel = Application.loadedLevel;
PlayerPrefs.SetInt("LastLevelLoaded",currentLevel);
}
}
Sundar
2
use PlayerPrefs to store current level as previouslevel when you go to next level.
Then call previouslevel OnMouseDown(){}
instead of Awake, make it a unique function:
function LoadLastLevel()
{
//retrieve and load last level played.
DontDestroyOnLoad(gameObject);
currentLevel = PlayerPrefs.GetInt("LastLevelLoaded");
Application.LoadLevel(currentLevel);
}
then on the cube:
var gameLoader : LevelLoadManager;
function Start(){
gameLoader = GameObject.Find("LoaderObjectName").GetComponent(LevelLoadManager);
}
function OnMouseDown(){
gameLoader.LoadLastLevel();
}