UI button doesn't work when it's above my game board
Hello, everyone. For an end of year project, I have to use my teacher's code to create the numerical variant of a board game. For the moment, I'm replacing some buttons but my problem comes when I want to click on them. When it is visually above the board, the button doesn't work. I can't figure out where the problem comes from. I try to use a "!EventSystem.current.IsPointerOverGameObject()" but nothing works.
Would you know where the problem could come from? Thank you very much everyone.
PS: Sorry for my bad English, I'm French and I use a translator.
PS2: The first button only works if I click it but without being above the tray.
Answer by kbop2000 · Apr 21, 2020 at 03:03 AM
you try use OnClick() method in Button Component ?
Well, when in my code I instantiate my buttons, I put the highlighted line of code in the image so that I can assign them a method in their "OnClick".
oh sorry, i mistake question .. if you use RectTransform, try this
void Update()
{
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition))
{
Debug.Log("$$anonymous$$ouse Over!");
}
}
I don't think he's using RectTransform. Sorry if I'm not clear, this is my $$anonymous$$cher's base code and it's up to me to modify it to fit what I have in $$anonymous$$d. By moving the Panel where the buttons are located, they work perfectly. It is really when they are above the tray that the button can be clicked but nothing happens.
Your answer
Follow this Question
Related Questions
Custom functions in button click not working after build 1 Answer
Execute code when clicked anywhere except on UI buttons 1 Answer
UI Buttons do not work when material is applied to it? 0 Answers
Is there a way to detect if a button is pressed if it isn't created programatically? 2 Answers
How do I catch a click on a non-interactable button? 1 Answer