- Home /
Loading Sene problem
So Im making my first "minigame" I guess, So when i hit the finish line this gui pops up, on one of the buttons it says next(thats for next level). Currently I have three scenes: Level1, Level2, Level3. I can press next and get to Level2 but it doesn't work on Level3 (I Have a different script for each level)
Nextscript from 1 to 2 using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class NextScript : MonoBehaviour {
public Button NextBtn;
public Text NextBtnTxt;
// Use this for initialization
void Start () {
NextBtn.onClick.AddListener(onClicked);
}
// Update is called once per frame
void onClicked () {
NextBtn.enabled = false;
NextBtnTxt.enabled = false;
SceneManager.LoadScene("Level2", LoadSceneMode.Single);
}
}
NextScript from 2 to 3
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class NextScriptLvl2 : MonoBehaviour {
public Button NextBtn1;
public Text NextBtnTxt1;
// Use this for initialization
void Start () {
NextBtn1.onClick.AddListener(onClicked1);
}
// Update is called once per frame
void onClicked1 () {
NextBtn1.enabled = false;
NextBtnTxt1.enabled = false;
SceneManager.LoadScene("Level3", LoadSceneMode.Single);
}
}
again First one works great, the second one doesn't
Answer by hexagonius · Oct 20, 2018 at 10:52 AM
Reducing code duplication is always a good practive to avoid dealing with errors you have to correct in multiple places. In this case, you can make the level name a public string variable and use the same script in every scene, typing the next level name in the inspector. Despite that fact, either the scene is not spelled right, the scene looks identical to the other and you just THINK it did not work, or you forgot to add the scene to the build settings.
Answer by ligiskegjerde · Oct 20, 2018 at 11:14 AM
The scenes are different and they are all in the build settings, but I will try your suggestion
Well I found out I had tried to use the same script for the reset button as my next button and I had just blended them together, I'll do some more playtesting to see if it works
Your answer
Follow this Question
Related Questions
Does scene loading improve performance? 1 Answer
Webplayer hangs on loading scene 2 Answers
What Happens in Scene Load 1 Answer
Main Scene keeps becoming corrupted randomly. 0 Answers
Not loading scene on build 1 Answer