• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Misthra-Games · Jan 16, 2016 at 08:24 AM · c#sceneloadscene-loadingcurrent

Get current scene number

Hey. I was wondering if anyone could tell me how to get the current scene NUMBER. I know how to get the current scene. But what im trying to do is something like "int nextScene = currentScene + 1;" So that i can load the next scene no matter what scene it is. Could someone tell me how?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vintar · Jan 16, 2016 at 12:30 PM 1
Share

I think maybe Scene$$anonymous$$anager.GetActiveScene().buildIndex.

But note from the docs :

Returns the index of the scene in the Build Settings. Always returns -1 if the scene was loaded through an AssetBundle.

3 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by Alakanu · Feb 23, 2016 at 02:07 PM

Hey man, I was having the same struggle today. I think the solution is

sceneID = SceneManager.GetActiveScene().buildIndex;

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image echoMike · Oct 23, 2017 at 06:50 AM 0
Share

That's very helpful. It appears that I'm still not fully understand Struct, which is why I'm searching for this.

avatar image
0

Answer by hexagonius · Jan 16, 2016 at 12:58 PM

I think grabbing all scenes, writing them to a static array and then getting the index for the current scene of that array might be a good idea:

http://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.GetAllScenes.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by x_mtd_x · Mar 18, 2017 at 05:46 PM

 //in top of youre script
 using UnityEngine.SceneManagement;
 
 
     // gets the curent screen
     Scene sceneLoaded=SceneManager.GetActiveScene();
     // loads next level
     SceneManager.LoadScene(sceneLoaded.buildIndex +1);

thats the new trick greethings Mathieu Dijkstra

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

63 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

After reloading the scene twice one script doesn't work. 0 Answers

Can anyone tell me what the issue is with my code? (C#) 1 Answer

C# SceneManager script not loading next scene after (seconds) 4 Answers

SceneManager.LoadScene is crashing or freezing for Android Devices 3 Answers

Only half of work/wall spawping after die and restart game,Why load after die only half scene? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges