Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How to avoid multiple mouse clicks registering in OnGUI?

$
0
0
I have a character portrait with GUI.Box that when clicked hides the portrait and disables the box, and then shows the character's inventory with a new GUI.Box in the same space as before that when clicked does the opposite (hide inventory, disable box, show portrait again). Now, since OnGUI plays multiple times per frame, it registers my mouseclick twice and thus if I click on the portrait it enters inventory mode for a fraction of a second (actually too fast to even see) and then immediately hides it again because the new box in the inventory mode also gets activated by the same mouseclick, which is kinda annoying. Is there any way to avoid this issue? if(ShowInventory == false && HidePortrait == false) { GUI.DrawTexture (Rect (100, 100, PortraitWidth, PortraitHeight), Portrait); var CharacterPortrait = new Rect(100, 100, PortraitWidth, PortraitHeight); GUI.Box(CharacterPortrait,"Portrait"); if (CharacterPortrait.Contains(Event.current.mousePosition)) { if(Event.current.type == EventType.MouseDown && Event.current.button == 0) { ShowInventory = true; HidePortrait = false; } if(ShowInventory == true) { GUI.DrawTexture (Rect 100, 100, PortraitWidth, PortraitHeight), Portrait); var CharacterPortraitInv = new Rect(100, 100, PortraitWidth, PortraitHeight); GUI.Box(CharacterPortraitInv,"Portrait"); if (CharacterPortraitInv.Contains(Event.current.mousePosition)) { if(Event.current.type == EventType.MouseDown && Event.current.button == 1) { ShowInventory = false; HidePortrait = false; }

Viewing all articles
Browse latest Browse all 171066

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>