© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
Spontini

❔ My Level Number keep returning as 0 (Unity)

Hello, I'm new at both Unity and coding. Here is my issue,
Debug.Log(levelNu);
Debug.Log(levelNu);
keep returning as
0
0
even while I am at Scene 2, 3, 4. How can I fix this?
   int levelNu;

    void Update()
    {
        Debug.Log(levelNu);
    }

    public void LoadNextScene()
    {
        int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
        int nextSceneIndex;
        nextSceneIndex = ++currentSceneIndex;
        if (currentSceneIndex == SceneManager.sceneCountInBuildSettings)
        {
            nextSceneIndex = 0;
        }
        SceneManager.LoadScene(nextSceneIndex);
        levelNu = currentSceneIndex;
    }
   int levelNu;

    void Update()
    {
        Debug.Log(levelNu);
    }

    public void LoadNextScene()
    {
        int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
        int nextSceneIndex;
        nextSceneIndex = ++currentSceneIndex;
        if (currentSceneIndex == SceneManager.sceneCountInBuildSettings)
        {
            nextSceneIndex = 0;
        }
        SceneManager.LoadScene(nextSceneIndex);
        levelNu = currentSceneIndex;
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Unity property unityaction invoke
C#CC# / help
3y ago
✅ Unity Super Mario level assistance
C#CC# / help
4mo ago
Truncating 1 and 0 and returning as a double
C#CC# / help
2y ago