How can I ignore background under UI for clicking?
So I have gameobjects I can click on and drag anywhere on the screen.At the same time there are buttons to rotate,move and adjust their mass etc.So I write a script to background that when I click on background,I deselect my object and buttons for them disappear.But when I click my button(say rotate button) button works,but my click also detects background and my buttons disappear.How can I solve this?
Thanks in advance and sorry for my english.
Do you check it in OnGUI or Update?
You should use comment, not a real Answer.
Answer by CaptainKirby · Sep 01, 2015 at 11:40 AM
When selecting objects(not ui), check if the pointer is above a ui element(asuming that you have an event system in the scene):
bool t = UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject ();
if t is true then the pointer(mouse) is on top of a ui element and you should tell it to not do anything. This can also work for touch but is a bit more involved.
Your answer
Follow this Question
Related Questions
UI Canvas draw order 1 Answer
Standard Assets First Person Controller hiding cursor after changing scenes 1 Answer
Problem with UI Text in Google VR 0 Answers
How to hide world space canvas behind walls? 0 Answers
UI Not Displaying 1 Answer