Search Unity

GUI.Buttons at same position

Discussion in 'Immediate Mode GUI (IMGUI)' started by nTu4Ka, May 15, 2015.

  1. nTu4Ka

    nTu4Ka

    Joined:
    Jan 27, 2014
    Posts:
    69
    Hi,

    If there'll be two GUI.Buttons at same position, e.g. a banner and a close button at it's edge when click is performed on top button - will both button trigger?

    E.g.

    if (GUI.Button(new Rect(0, 0, 300, 500), MainTexture)) {
    //this is big banner button
    }
    if (GUI.Button(new Rect(0, 0, 100, 100), CloseBtnTexture)) {
    //this is close button, hide button from above
    }

    If so? How to prevent other buttons trigger when clicking on close button
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    No only one button will handle the click. The order you draw your buttons in will determine which is considered on top, look at GUI.depth to have more precise control over this although you will need to place your buttons into separate OnGUI calls.
     
  3. nTu4Ka

    nTu4Ka

    Joined:
    Jan 27, 2014
    Posts:
    69
    Hi!

    Thanks!
    I think GUI.depth may solve my problem.

    As of now i'm drawing button that has to be on top with a box which isn't an elegant solution:
    GUI.Button(...); //close button - receives click first and disables second button
    GUI.Button(..., BannerTexture); //banner button
    GUI.Box(..., CloseTexture); //close button texture