Search Unity

OnGUI over GUITexture : no event triggered. Any solution ?

Discussion in 'Immediate Mode GUI (IMGUI)' started by KevS, Nov 5, 2012.

  1. KevS

    KevS

    Joined:
    Apr 21, 2010
    Posts:
    51
    Simple case : put a OnGUI element over a GUIElement. For instance, a GUI.Box over a GUITexture (see attached img).
    It seems that the part of the GUITexture "hidden" by the GUI.Box doesn't trigger the "OnMouse" events (i.e OnMouseEnter/OnMouseStay/OnMouseExit functions of an attached script). Somehow as expected :)

    My problem is that I would like that it works.(in my case, the GUI.Box is a chat window and the GUITexture is a part of some context menu displayed on click on the scene).
    To what I know and what I searched, it's unfortunately not possible to solve that.

    There is the solution to convert the context menu with the OnGUI system (or to convert the chat system with GUIElements ... not sure if it could be a good idea xD) but if you have any quicker solution, it could save my day... :roll:
     

    Attached Files:

  2. Whatbadguy

    Whatbadguy

    Joined:
    Apr 10, 2011
    Posts:
    165
    You can use Rect.Contains to determine whether the mouse is over the texture and if you click while over your texture.
     
  3. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    This is due to a known bug, or a necessity from UT perspective (they advocate popping up things using the GUI.Window exclusively).

    I've had the same problem with this when relying on Unity's GUI handling. Things with buttons could easily be solved using the "do your own Rect calculations" approach mentioned above, but when having scrollbars overlapping, there's no way out except building your own scrollbar system (which I am planning to do for my framework).