C
C#2y ago
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); keep returning as 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;
}
3 Replies
phaseshift
phaseshift2y ago
You might be creating more than one of whatever class that is.
Elmishh
Elmishh2y ago
Whats nextSceneIndex = + +currentSceneIndex
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server