- Home /
Why are no functions showing on my button
Please dont reference another post none have worked for me plz ty my script and yes its public and the script is on an empty game object
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class MainManuControlScript : MonoBehaviour {
public Button level02Button, level03Button, level04Button, level05Button, level06Button, level07Button, level08Button, level09Button;
int levelPassed;
// Use this for initialization
void Start () {
levelPassed = PlayerPrefs.GetInt ("LevelPassed");
level02Button.interactable = false;
level03Button.interactable = false;
level04Button.interactable = false;
level05Button.interactable = false;
level06Button.interactable = false;
level07Button.interactable = false;
level08Button.interactable = false;
level09Button.interactable = false;
switch (levelPassed) {
case 1:
level02Button.interactable = true;
break;
case 2:
level02Button.interactable = true;
level03Button.interactable = true;
break;
case 3:
level02Button.interactable = true;
level03Button.interactable = true;
level04Button.interactable = true;
break;
case 4:
level02Button.interactable = true;
level03Button.interactable = true;
level04Button.interactable = true;
level05Button.interactable = true;
break;
case 5:
level02Button.interactable = true;
level03Button.interactable = true;
level04Button.interactable = true;
level05Button.interactable = true;
level06Button.interactable = true;
break;
case 6:
level02Button.interactable = true;
level03Button.interactable = true;
level04Button.interactable = true;
level05Button.interactable = true;
level06Button.interactable = true;
level07Button.interactable = true;
break;
case 7:
level02Button.interactable = true;
level03Button.interactable = true;
level04Button.interactable = true;
level05Button.interactable = true;
level06Button.interactable = true;
level07Button.interactable = true;
level08Button.interactable = true;
break;
case 8:
level02Button.interactable = true;
level03Button.interactable = true;
level04Button.interactable = true;
level05Button.interactable = true;
level06Button.interactable = true;
level07Button.interactable = true;
level08Button.interactable = true;
level09Button.interactable = true;
break;
}
}
public void levelToLoad (int level)
{
SceneManager.LoadScene(level);
}
}
Answer by fibeesoft_unity · Aug 24, 2020 at 03:02 PM
Hmm, there are few things... First of all, I can't see you setting the PlayerPrefs and it looks like your levelPassed variable will always get 0. You don't have such an option in your Switch, that's why nothing is happening.
Secondly, you should use default in the Switch.
More over it would be better to add yours button to the array (or create them at runtime) and use a loop to make them active or inactive depending on the levelPassed value.
Your answer
![](https://koobas.hobune.stream/wayback/20220613010259im_/https://answers.unity.com/themes/thub/images/avi.jpg)