- Home /
Dropdown/combobox does not expand or collapse completely on click
Hi guys, New to Unity programming. Haven't been exposed to any gaming stuff in school yet. I've looked at various tutorials and read quite a bit of documentation, but just not clear on this. I have a main menu with sub buttons that should appear on click. I'm using scale on the Y to have the sub buttons expand and collapse on click.
The problem is they slowly collapse on multiple clicks. I'd like to be able to click the main button and have the sub buttons expand and on-click again have them collapse on-click. Thanks for any feedback!
public RectTransform submenu;
private int indexVal;
void Start ()
{
submenu = transform.FindChild ("Container").GetComponent<RectTransform>();
indexVal = 0;
}
public void Update()
{
if (indexVal == 0) {
if (Input.GetMouseButtonDown (0)) {
Vector3 scale = submenu.localScale;
scale.y = Mathf.Lerp (scale.y, 1, Time.deltaTime * 12);
submenu.localScale = scale;
indexVal = 1;
}
} else {
Vector3 scale = submenu.localScale;
scale.y = Mathf.Lerp (scale.y, 0, Time.deltaTime * 12);
submenu.localScale = scale;
indexVal = 0;
}
}
Comment