- Home /
Question by
ParyPro · Sep 02, 2019 at 06:04 PM ·
scripting problembug
Level Select screen Messed Up - Please help!
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");
}
}
139344-pasted-image-0-1.png
(349.3 kB)
Comment