unity3d - Unity2d: return to previous application on button click -


is there way of returning previous game application when close unity/close game application on button press. have scene button in it, if player press button, bring them new level (scene 1). want save scene (scene 2) using playerprefs keep tabs on if close game application, or close unity , re-open , play application (regardless of scene in) game should automatically bring me scene 2. possible return previous application (even if close application or game) on button click? if button clicked on, , exit out of application , or game, re open , play game should automatically bring me scene exited out of (scene 2)

when ever application quit event called, save current scene player preference.

using unityengine.scenemanagement;   void quitgame() {     scene currentscene =  scenemanager.getactivescene();     playerprefs.setstring("lastscenename",currentscene.name);     application.quit(); } 

above code save name of current scene @ time of application quit.

now when restart game , scene(0) loaded. call following method in start() or awake() function.

void loadlastscene() {     if (playerprefs.getint("isfirsttime") == 0) //this make sure chunk of code doen't run on first usage.     {         playerprefs.setint("isfirsttime", 1);     }     else if (playerprefs.getint("isfirsttime") == 1)     {     scenemanager.loadscene(playerprefs.getstring("lastscenename"));     } } 

code not tested.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -