So i want this problem with ui buttons done
So I have a few UI buttons. But I also have a script which refers to a ray and raycast and removes the buttons if nothing is clicked on or changes the buttons which are displayed depending on what gameobject is clicked on. My problem is that when I try to click on a button, Unity interprets it as not clicking on anything and removes the buttons, so nothing ever gets done. Ideally, I want the code to look something like this
if (Input.GetMouseButtonDown (0)) {
if (Physics.Raycast (ray, Mathf.Infinity)) { if (hit.transform.gameObject.tag == "Tile") {
//do a thing } } }
How do I set this sort of process up or what should I refer to? Ive looked around and can't find a proper answer or it's explained in a way I don't really understand. Thank you in advance.
Answer by hexagonius · Jan 24, 2016 at 08:27 AM
check with EventSystem.current.currentSelectedGameobject before raycasting. If your code is executed prior to the Unity Eventsystem, change its execution order to execute later.
How would I do that? would it be something like if (EventSystem.current.currentSelectedGameobject == ui button) do thing else execute script
could I trouble you with an example?? Thank you
Your answer
Follow this Question
Related Questions
Why can't spam click on UI Image ? 0 Answers
UI Button Mouse Area is not working correctly! 0 Answers
How do I press an UI button with Gamepad controls? 0 Answers
UnityEvents for UI updating, generic way of removing repeated calls in same frame. 0 Answers
UI button not working (2D) [Solved] 2 Answers