/// <summary> /// Creates a button to display in the box hide menu from a given id. /// </summary> public void DisplayIcon(BoxHideInteractable obj, int id) { if (current_icons == 2) //Max number of icons { return; } BoxHideButton button = Instantiate(button_prefab) as BoxHideButton; button.transform.SetParent(transform, false); button.icon.sprite = obj.options[id].icon; button.function = obj.options[id].function; button.name = obj.options[id].name; //Seach free position if (current_icons == 0) { button.transform.localPosition = pos_A; } else { button.transform.localPosition = pos_B; } buttons.Add(button); current_icons++; }
/// <summary> /// Removes a button in the box hide menu from a given id /// </summary> public void HideIcon(BoxHideInteractable obj, int id) { BoxHideButton button = buttons.Find(x => x.name == obj.options[id].name); //Find button to remove if (button != null) //Desired button to delete found { buttons.Remove(button); //Remove from list Destroy(button.gameObject); //Remove the object current_icons--; //Repositioning of the first icon to position A if (current_icons == 1) { buttons[0].transform.localPosition = pos_A; } if (current_icons == 0) //Remove the menu because no one is hide { HideMenu(); } } }