//Collect the game object
public GameObject sorting;
//Collect the button
public GameObject[] sortingBtn;
int j;
int b;
void Start () {
sorting = GameObject.FindGameObjectsWithTag("Sort");
sortingBtn = GameObject.FindGameObjectsWithTag("SortButton");
for (j = 0; j < sorting.Length; j++)
{
Debug.Log(j + " " + sorting[j].name);
}
for (b = 0; b < sortingBtn.Length; b++)
{
Debug.Log(b + " " + sortingBtn**.name);**
}
Invoke(“CurrentScene”, 1);
}
public void CurrentScene()
{
switch (b)
{
case 1:
Debug.Log(“Plastic hellooo”);
sorting[1].SetActive(true);
sorting[0].SetActive(false);
break;
case 0:
Debug.Log(“Paper hellooo”);
sorting[0].SetActive(true);
sorting[1].SetActive(false);
break;
default:
Debug.Log(“Default hellooo”);
sorting[0].SetActive(true);
sorting[1].SetActive(false);
break;
}
}
The case default works well at the beginning. But when click the UI button to switch the case it doesn’t work.
How to make the button respond to the condition that has be set in switch case statement? (The button had been attached with pubic void CurrentScene in Unity).