Search Unity

UI buttons on a panel not working

Discussion in 'UGUI & TextMesh Pro' started by zcoursey, May 22, 2017.

  1. zcoursey

    zcoursey

    Joined:
    May 18, 2017
    Posts:
    16
    I can open up this panel and close it just fine with a separate button, but the four buttons on this panel are completely non-responsive. I have an EventSystem and I believe all the buttons are correctly linked to where they should be.

    Code (CSharp):
    1. public GameObject chao;
    2.     public GameObject chaoPanel;
    3.     public GameObject[] chaoList;
    4. void Start()
    5.     {
    6.         if (!PlayerPrefs.HasKey("looks"))
    7.         {
    8.             PlayerPrefs.SetInt("looks", 0);
    9.             createChao(PlayerPrefs.GetInt("looks"));
    10.         }
    11.     }
    12. public void buttonBehavior (int i)
    13.     {
    14.         switch(i)
    15.         {
    16.             case (0):
    17.             default:
    18.                 chaoPanel.SetActive(!chaoPanel.activeInHierarchy);
    19.                 break;
    20.             case (1):
    21.                 break;
    22.             case (2):
    23.                 break;
    24.             case (3):
    25.                 if (MusicPlayer.GetComponent<AudioSource>().isPlaying)
    26.                 {
    27.                     MusicPlayer.GetComponent<AudioSource>().Pause();
    28.                 }
    29.                 else
    30.                 {
    31.                     MusicPlayer.GetComponent<AudioSource>().UnPause();
    32.                 }
    33.                 break;
    34.             case (4):
    35.                 chao.GetComponent<Chao>().saveChao();
    36.                 Application.Quit();
    37.                 break;
    38.         }
    39.     }
    40.     public void createChao (int i)
    41.     {
    42.         if (chao)
    43.         {
    44.             Destroy(chao);
    45.             chao = Instantiate(chaoList[i], new Vector3(0,0,-2), Quaternion.identity) as GameObject;
    46.         }
    47.         if (chaoPanel.activeInHierarchy)
    48.             chaoPanel.SetActive(false);
    49.         PlayerPrefs.SetInt("looks", i);
    50.     }
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Do the buttons have OnClick events set to this script? Are they calling 'buttonBehaviour' and passing an integer?
    Is this script on an object in the scene?
    Anything else - maybe I misunderstood? :)
     
  3. zcoursey

    zcoursey

    Joined:
    May 18, 2017
    Posts:
    16
    Yeah they are all calling buttonBehavior and linked to a function in the script. That's why I'm so confused. I have other buttons set up just like them from what I can see and they work just fine.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ya, that doesn't sound good/right.. Not sure what else to say if you believe everything is setup correctly. :(