Reputation: 75
i'm trying to show and hide a menu from a screen with mouse right click. For example, when the right click is clicked, a menu appears and when it's pressed again, the menu hides.
int flag = 1;
void Update()
{
if (Input.GetMouseButton(1))
{
if(flag == 1)
{
RadialMenuSpawn.ins.SpawnMenu(this); //Show it
flag = 0;
}
if(flag == 0)
{
/* hide it */
flag = 1;
}
}
}
Is there any command to hide that menu from the screen because it's copying itself?
Upvotes: 0
Views: 1872
Reputation: 565
Simply store all of your menu objects in an array and when you right click you loop through that array, enabling/disabling the objects.
public GameObject[] menuObjects;
private bool _menuState = false;
void Update()
{
if(Input.GetKeyDown(KeyCode.Mouse1))
{
// Change the value of _menuState
_menuState = !_menuState;
// Loop through the menu objects
foreach(GameObject obj in menuObjects)
{
// Enable/Disable the objects
obj.SetActive(_menuState);
}
// Do other stuff...
}
}
Upvotes: 1