There is 1 scene on it, a button that takes me to another scene, how to make a check on this button, so that if I already clicked on this button, then this scene did not load anymore, but the one on which I switched for the first time was loaded.

  • the dumbest option is, if there are only two scenes, then get a static variable short sceneIdx in which, when clicked, change the index of the scene. sceneIdx = sceneIdx == 1 ? 0 : 1 sceneIdx = sceneIdx == 1 ? 0 : 1 .... and then load the scene with the LoadScene(sceneIdx) index ...... actually, if there are more than two scenes, then the condition of the problem is not to be fulfilled in principle - Alexey Shimansky
  • And if we allow placing the panel with the choice of three scenes on the first scene, and is it possible to make this panel active only with a single first entry into the game, in which he can make a choice on the transition from 3 scenes. And when entering the game further, the same first scene was loaded, but without the panel, but only with one button that would switch to the scene that he chose when he first entered the game? - Grade Rustam Houten
  • one
    Can. This is called saving. and reading from saved data - Alexey Shimansky
  • Can you explain something by an example? Or what you need to use? I would be very grateful - Grade Rustam Houten

1 answer 1

You make a dummy scene on which you make a script in which you check:

  string firstScene = "firstScene"; string nameScene = PlayerPrefs.GetString("SelectedSceneWhenFirstEnterInGame",string.Empty); SceneManager.LoadScene( nameScene == string.Empty?firstScene: nameScene, LoadSceneMode.Single); 

It is best to save the name of the scene, because it is easier to keep track of the name than the index (added the scene and the order of the indexes has shifted).

On the firstscene when you press the button you do:

 PlayerPrefs.SetString("SelectedSceneWhenFirstEnterInGame", selectedScene); SceneManager.LoadScene( selectedScene, LoadSceneMode.Single); 

where selectedScene is the name of the selected scene.