Advertisement
hhac

Get all scene in unity

Dec 3rd, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. // Code snip to Get all scene in unity
  2. public void UnlockNextLevel()
  3. {
  4.     int sceneCount = SceneManager.sceneCountInBuildSettings;
  5.     string[] scenes = new string[sceneCount];
  6.     for (int i = 0; i < sceneCount; i++)
  7.     {
  8.         scenes[i] = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i));
  9.     }
  10.  
  11.     var nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
  12.  
  13.     if (nextSceneIndex <= sceneCount - 1 && scenes[nextSceneIndex].StartsWith("Level", StringComparison.Ordinal))
  14.     {
  15.         PlayerPrefs.SetString(scenes[nextSceneIndex], "unlocked");
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement