load level issue
good morning all i got a problem :- when i "complete level" unity should load next level but it doesnt it gives random things it may load the main menu or just do nothing it shows the continue button to next level but it doesnt load it , enemies keep moving and i am at goal i can move and do everything like if i didnt finish the level it happened when i tried to add something to my code that reset timer , i deleted that reset code but the problem still exists ,now i dont even know what happened, i had a problem like that but idk how i fixed it i will give u the code i hope u help me
public int currentLevel = 0;
void Start()
{
if (PlayerPrefs.GetInt("Level Completed") >2)
{
currentLevel = PlayerPrefs.GetInt("Level Completed");
}
else
{
currentLevel =0;
}
}
public void LoadNextLevel()
{
Time.timeScale = 1f;
if (currentLevel <= 6)
{
currentLevel += 1;
print(currentLevel);
SaveGame();
Application.LoadLevel(currentLevel);
}
else
{
print("You Win!");
}
}
public void SaveGame()
{
PlayerPrefs.SetInt("Level Completed", currentLevel);
PlayerPrefs.SetInt("Level " + currentLevel.ToString() + " score", currentScore);
}
Answer by mwnDK1402 · Jun 19, 2016 at 08:41 PM
In your using statements add this namespace:
using UnityEngine.SceneManagement;
After that, you can replace the deprecated method "Application.LoadLevel" with this:
SceneManager.LoadScene(currentLevel);
This should work if you've updated Unity recently.
Answer by amrali5 · Jun 20, 2016 at 10:50 AM
okay thx bro i will try it , my unity version is 5.3.5f1
Your answer
Follow this Question
Related Questions
load level 1 Answer
Loading Particular UI from Different Scene 0 Answers
About Loading Scene 1 Answer
SceneManager.LoadScene(); is not working correctly 0 Answers
I want to delay 3 sec to load next level after the collision in C# 1 Answer