I use two-button to set the index value, once I click it gave value to the index.
public class tabbar : MonoBehaviour
{
private int index = 0;
public int buttonindex;
public GameObject[] pannels;
// Update is called once per frame
void Update()
{
for (int i = 0; i < pannels.Length; i )
{
if (i == index)
{
pannels[i].SetActive(true);
}
else
{
pannels[i].SetActive(false);
}
}
}
public void IWasClicked()
{
index = buttonindex;
}
}
the first one is ok to set 0,but the second one no work?? any ideas?
CodePudding user response:
Try this and don't forget to update your buttonIndex:
public class tabbar : MonoBehaviour
{
public int buttonIndex;
public GameObject[] pannels;
private void UpdatePannels(int index)
{
for (int i = 0; i < pannels.Length; i )
{
pannels[i].SetActive(i == index);
}
}
public void IWasClicked()
{
UpdatePannels(buttonIndex);
}
}
