Question by
x76 · Jan 14, 2019 at 07:42 PM ·
level load
level contiune problem
i try to level continue button but dont work. for example; im in level 4 but exit the game and push the continue button, game start level 3.
scripts: level button:
> private int currentSceneIndex;
>
> public void loadA(string scenename)
> {
> SceneManager.LoadScene(scenename);
> currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
> PlayerPrefs.SetInt("SavedScene", currentSceneIndex);
> }
continue button:
private int sceneToContiune;
public void contiuneGame()
{
sceneToContiune = PlayerPrefs.GetInt("SavedScene");
if (sceneToContiune != 0)
SceneManager.LoadScene(sceneToContiune);
else
return;
}
Comment
Best Answer
Answer by Hellium · Jan 14, 2019 at 07:50 PM
// Load level button
public void loadA(string scenename)
{
PlayerPrefs.SetString( "SavedScene", scenename );
SceneManager.LoadScene(scenename);
}
// Continue button:
public void continueGame()
{
string sceneName = PlayerPrefs.GetString("SavedScene", null);
if ( sceneName != null )
SceneManager.LoadScene(sceneName);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612185743im_/https://answers.unity.com/themes/thub/images/avi.jpg)