Search Unity

My UI button isnt working

Discussion in 'Getting Started' started by Petras99, May 31, 2016.

  1. Petras99

    Petras99

    Joined:
    May 29, 2016
    Posts:
    27
    I have a canvas with a button that appears when the player passes the finish line. However the button doesnt work. I have read through many other forums about a button not working, but none of them have worked for me.
    upload_2016-5-31_12-39-56.png

    upload_2016-5-31_12-40-22.png

    upload_2016-5-31_12-40-46.png

    I have an event system, and a graphics raycaster on my canvas. I have another canvas that displays the time while the person is still playing. However my script disables that canvas and enables the one with the button when the player passes the finish line. Any responses are appreciated. i also disable my camera when the player passes the finish line.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Button doesn't work? Can you be a little more descriptive? Is the button visible? Does the button respond to the mouse pointer moving over it? Does it tint on the click?

    One thing to check if to put a Debug.Log in the method the button is calling. That way you can see if the problem is in the button or in the code.
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Also, if you select the EventSystem in the Hierarchy and then watch it in the Inspector while you test your game, you can get all sorts of interesting information about where the events are going.
     
    Kiwasi likes this.
  4. Petras99

    Petras99

    Joined:
    May 29, 2016
    Posts:
    27
    The button shows up, it changes color when its clicked, and when the mouse is hovered over it. I will try the debug log.
     
  5. Petras99

    Petras99

    Joined:
    May 29, 2016
    Posts:
    27
    Okay ill try it!
     
  6. Petras99

    Petras99

    Joined:
    May 29, 2016
    Posts:
    27
    I figured it out! I have a script that uses OnGUI, so if i disable that it works.
     
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Thanks for reporting back. I guess your OnGUI code was swallowing the event.
     
  8. Petras99

    Petras99

    Joined:
    May 29, 2016
    Posts:
    27
    Yep, that gave me such a headache for such an easy fix. Thank you for your response! Your suggestion to look at the event system was interesting.