Question by
FlyingOlsen · Sep 12, 2016 at 04:41 AM ·
uiscripting beginnerbuttonstates
Changing interactivity of a button with another button
I have three buttons that when one is inactive the others have to be active. When another button is pressed, the other needs to be reactivated. Code snippet for two buttons:
public Button collectFood;
public Button collectScience;
void Update ()
{
foodText.text = "Food:" + " " + Mathf.Round(food);
scienceText.text = "Science:" + " " + Mathf.Round(science);
if (collectScience.interactable == false)
{
scienceCollect();
collectFood.interactable = true;
Debug.Log("Collect science is enabled");
}
if (collectFood.interactable == false)
{
foodCollect();
collectScience.interactable = true;
Debug.Log("Collect food is enabled");
}
}
They can exchange each others interactable bools, but it seems something in the Update function causes the collectFood.interactable=true; line to be held continuously, thereby making it impossible to trigger the click event for Button collectScience. Can someone tell me how to get around this?
Thank you in advance. (Respondents keep in mind i am a beginner)
Comment