[resolved] How do I deactivate a button once its height is < 40 in c#
I have a button that is a parent to other buttons. When a child button is clicked it deactivates and the height of the parent button shrinks. The parent button has a height of less than 40 when all of the children have been deactivated. Any time one or more children are active the height is grater than 40. When all of the children are deactivated, I want the parent to deactivate because it is empty.
I feel it will be easier to use the height of the parent button to determine whether or not it is empty, as opposed to finding out how to check to see if all of the children are deactivated. Therefore, height is the trigger I intend to use. However, if there is an easy way to check to see if all of the children are deactivated and use that information as a trigger, I would be willing to give it a try.
For now this is what I have for the function.
public void ifEmpty(GameObject topic)
{
if (topic.GetComponent<RectTransform>().rect.height < 40)
{
topic.SetActive(false);
}
}
I set the parent button as the "topic" and have the children set to activate the function each time they are clicked.
It is not working. Any help would be appreciated :)
Update: I added a counter to the parent button. Each time children are added to the parent button the counter increments by 1. Each time a child is deactivated the counter is decremented by 1 and an if statement is run to see if the counter is <= 0. If so then the parent is deactivated. This seems to have gotten things working! :D