- Home /
This question was
closed Oct 21, 2017 at 04:22 PM by
unity_G2yrNlWYdpJKuw for the following reason:
The question is answered, right answer was accepted
Question by
unity_G2yrNlWYdpJKuw · Oct 19, 2017 at 04:46 PM ·
scenevariableglitchint
Problem with loading scenes...
Hi, so basically I have a scene that is called PreLoader and it basically loads a scene from where you left off. Now I have this script :
public int level_index;
void Start () {
Scene currentScene = SceneManager.GetActiveScene ();
string sceneName = currentScene.name;
if (sceneName == "PreLoader") {
} else {
level_index++;
PlayerPrefs.SetInt ("LevelSave", level_index);
}
}
I set the level_index to be 1. But when I start the game the level_index changes to 0? Why? Is there anything wrong or is it a bug or something?
I also have this script which loads the last level it was on.
AsyncOperation async;
public SaveLevel lvl;
public void Start ()
{
StartCoroutine (LoadingScreen ());
lvl.level_index = PlayerPrefs.GetInt ("LevelSave");
}
IEnumerator LoadingScreen ()
{
yield return new WaitForSeconds (1);
async = SceneManager.LoadSceneAsync (lvl.level_index);
async.allowSceneActivation = false;
while (!async.isDone) {
if (async.progress == 0.9f) {
async.allowSceneActivation = true;
}
yield return null;
}
}
}
Help would be much appriciated! Thanks :)
Comment
Follow this Question
Related Questions
How to use same code at multiple scenes ? 1 Answer
Scene as a variable 6 Answers
I can't print a int.ToString() variable in a guiText.text 1 Answer
Public variable not showing in Inspector(Solved) 1 Answer
Playerpref float is out of range? 1 Answer