- Home /
Ui button click on Canvas
I'm trying to restart my game with a button. I know the code to restart and I know how a button works. If I use the button an a single canvas it works but as I followed the Survival Shooter Tutorial I want the button to be part of the HUDCanvas so it's integrated in the animation of the gameoverscreen. So when my button is on the HUDCanvas it doesn't handle clicks. I have no idea why and I couldn't find the answer on the internet yet.
So here you can see where it is located and I know the problem has something to do with being on the canvas but It should be there I think.
As you can see I tried some different ways to do it, even the onclick.addeventlistener or something like that. Some of those ways did work when the button was on its own canvas but then it didn't show at the right time..
So if someone can help me it would be fantastic. Thanks in advance.
Answer by vanpeltj · Jan 30, 2015 at 09:18 PM
It didn't work by just selecting interactable but by selecting block raycasts. So your answer was certainly in the right direction. Thanks a lot!!
Answer by rob5300 · Jan 30, 2015 at 06:43 PM
If i remember correctly, the canvas in that project has raycasts to be ignored, as it was never intended to accept input in case it prevented the player from shooting properly.
You can fix this on the Canvas Group component on the HUDcanvas object. Re select Intractable.
More info here: http://docs.unity3d.com/Manual/class-CanvasGroup.html
(If this works, but causes problems for some reason, you can add a canvas group to the button or a parent of it, and have interacable selected as well as ignore parent groups.)