- Home /
Bug With My Level Select Screen
I have followed a Youtube video on this & tried to apply it to my own game. Upon dying in level 2, I am sent back to the Level Select menu (image attached) but the level 2 start button is still grayed out and locked despite the button On click settings being set up to how they should be. Attached is the script that should be handling that, and then the level control script. I believe the problem could possibly lie in the switch statement in my LevelSelectController.cs script, but I'm not sure exactly where or how I'd fix it. If anyone can find any suggestions or solutions to this problem they would be very much appreciated! Thanks!
public class LevelSelectController : MonoBehaviour {
public Button level02Button, level03Button;
int levelPassed;
void Start()
{
levelPassed = PlayerPrefs.GetInt("LevelPassed");
level02Button.interactable = false;
level03Button.interactable = false;
switch (levelPassed) {
case 1:
level02Button.interactable = true;
break;
case 2:
level02Button.interactable = true;
level03Button.interactable = true;
break;
}
}
public void levelToLoad (int level)
{
SceneManager.LoadScene (level);
}
public void resetPlayerPrefs()
{
level02Button.interactable = false;
level03Button.interactable = false;
PlayerPrefs.DeleteAll ();
}
}
public class LevelControlScript : MonoBehaviour {
public static LevelControlScript instance = null;
GameObject levelSign, gameOverText, youWinText;
int sceneIndex, levelPassed;
void Start()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
levelSign = GameObject.Find("LevelNumber");
sceneIndex = SceneManager.GetActiveScene().buildIndex;
levelPassed = PlayerPrefs.GetInt("LevelPassed");
}
public void youWin()
{
if (levelPassed < sceneIndex)
{
PlayerPrefs.SetInt("LevelPassed", sceneIndex);
}
}
public void youLose()
{
levelSign.gameObject.SetActive(false);
Invoke("loadMainMenu", 1f);
}
void loadMainMenu()
{
SceneManager.LoadScene("levelSelect");
}
}
start trying to fix the errors always showing in the console
Answer by Vaibhav_77 · Sep 04, 2019 at 11:10 AM
in LevelSelectController script in Start() you set level02Button.interactable = false;
Answer by mostashhed · Sep 04, 2019 at 04:17 PM
Check your build indexes and make sure that your level select menu placed at zero index. good luck!
Your answer
Follow this Question
Related Questions
First script plays animation but second script stops if from playing said animation 1 Answer
When switching scenes some of my scripts stop working 0 Answers
I'm trying to set a script to inactive 1 Answer
Attach to other coordinat SpringJoint2D from code. 0 Answers
How can i attach a script to many gameobject in array ? 1 Answer