|
If I use GUILayout, inside an if statement in OnGUI I get the following error:
Any idea how to use GUILayout inside an if statement? Thanks!
(comments are locked)
|
|
GUILayout is a pain like that sometimes, and this case is one which won't be easily solvable. What you could do is swap to GUI for just the tooltip - the code would be cleaner for your example anyway
Alternatively, you could use GUILayout to calculate the rects (by using GetRect), and then pushing them into the above function to actually draw the visible item Looks like I will be using GUI instead, thanks!
Dec 17 '10 at 04:48 PM
spaceshooter
Ah! Awesome, so it was just the GUILayout methods that cause this problem? Wow, thanks a ton!
Dec 17 '10 at 04:50 PM
Statement ♦♦
I have a box and 2 labels (text and a texture) so far and it seems to work :)
Dec 17 '10 at 05:19 PM
spaceshooter
(comments are locked)
|
|
I've dealt with stuff like this before; the solution is to check for EventType.Repaint, and use a separate variable that tracks whether the tooltip is active or not, so the layout stuff can be properly computed in the right order:
(comments are locked)
|

Paste the if-statement....
Yes... especially if you don't have an additional GUILayout outside of the if...
OnGUI is called multiple times per frame and expects the program flow to be static for some of the different -events-. Basically it's safe to switch flow on if (GUILayout.Button()) and other GUI calls, but if you're checking if a key is pressed you might run into troubles. Instead, try doing that in Update and set state variables. Or read in depth about how the GUI system works in the manual. In my personal opinion (and off topic rant), unitys gui is a real horror show where tons can go wrong and it's often not immediately clear what is the cause.
It is just: if (GUI.tooltip != "")
Added the full OnGUI example to the main post.