C# - Button doesn't go inactive after clicking another one but thats what I want
I have two buttons, general and other. If i click on general first, it goes active and other goes inactive. I click on other, but general is still active though I cant scroll through content anymore but i see the content. I click on other again and then both are enabled at the same time. This happens no matter if I click on other or general on the beginning, general activates either way heres the script thats supposed to make the buttons switch content:
public void Click()
{
if (sprite.sprite == neutral)
{
sprite.sprite = highlight;
achievementList.SetActive(true);
}
else
{
sprite.sprite = neutral;
achievementList.SetActive(false);
}
}
public void ChangeCategory(GameObject button)
{
AchievementButton achievementButton = button.GetComponent<AchievementButton>();
scrollRect.content = achievementButton.achievementList.GetComponent<RectTransform>();
achievementButton.Click();
activeButton.Click();
activeButton = achievementButton;
}
I don't really know what else should I include but i know something is wrong in this code I just dont know what
Answer by Fydar · Feb 26, 2016 at 03:13 PM
I would use:
gameObject.getComponent<Button>().interactable = false;
To make the button unusable after the button has been clicked.
I believe the issue lies in you attempting to access an inactive object, or you not setting to right object to be active again.
I don't know exactly what you mean in your question, but this might be a start.
Answer by ItsIcear · Feb 26, 2016 at 01:56 PM
Use a toggle UI element, you canset its function to call directly, then put in a script
// When clicked
toggle.GetComponent<Toggle>().active = false;