- Home /
The question is answered, right answer was accepted
Button onClick events will not be triggered
Hello,
I have a problem. In a "Canvas" element (GUI) I have a Panel. Inside this Panel I have a Button called "CloseBtn". This button should call a function called "hidePanel" in the "Panel" script assigned to the Panel. So I added the onClick event trigger in the inspector:
Unfortunately the HidePanel function will never be called. I also tried to create a empty Gameobject and added a script with a "test" function. Even then the test function will never be called.
So I thought a possible workaround would be to call the function manually with a onClick() function. So I created a script and assigned it to the button. But even then the "onClick" function will not be called:
I don't get any errors in the console. What is the problem here?
First guess is that your panel (or some other UI element) is "above" your buttons. (The panel is superior to your button in the scene hierarchy, and is consu$$anonymous$$g your clicks.) If so, re-order your buttons and interactables to the foremost position in the canvas hierarchy and see if that does it.
Do your other events invoke? (Does the button change to its highlight color when you mouse over it? Looks like you're missing an image - this would be worth adding one to test.)
I don't see public method HidePanel in your code
Answer by julmot · Mar 06, 2015 at 03:25 PM
The correct answer should be: make sure you have an EventSystem added to the hierarchy!
Follow this Question
Related Questions
In game right click menu 1 Answer
UI Button multiple parameters 6 Answers
Move gameobject to button in new 4.6? 0 Answers
OnPointerExit not updating if container panel was SetActive(false) 2 Answers