- Home /
prevent OnMousedown to trigger when 2 objects overlapping
case :
i want to make ui attached to a 3d object in real world,
-the cube is performing animation when clicked, the trigger is using onmousedown()
-also the ui button which is attached to the cube will toggle an info panel when clicked, the trigger also using onclick() on ui button
problem:
when i clicked on button, both of them perform their action instead only button triggering toggle info panel
i have tried:
i create a script to listen the event with unityevent, it subscribe to buttonscript and cubescript but then the editor not responding when played, now i have no clue
code
button script:
public void showConsole(){
Debug.Log("button clicked showconsole");
toggleClicked();
e_clickEvent();
Debug.Log(a+"<<<<<");
}
public void toggleClicked()
{
isActive = !isActive;
Debug.Log("panel is "+isActive);
}
*when clicked it trigger showconsole()
*please dont mind toggleClicked(), it only fill with debug log
cube script:
public void OnMouseDown()
{
// triggerAnim();
e_clickObj();
}
*please dont mind triggerAnim(), it only fill with debug log
image:
Answer by mchts · Mar 23, 2019 at 07:45 AM
In your mouseclick detection method you could do sth. like this:
if(EventSystem.current.IsPointerOverGameObject()){
if(!EventSystem.current.currentSelectedGameObject.name.Equals("name of your button")){
//perform cube animation if my button is not clicked
}
}
hi mchts, thanks for your reply.
you did solve my problem of (blocking click of two object ins$$anonymous$$d of one), what i want is block click on cube when i click on button -and succeed, but i think only using :
if(EventSystem.current.IsPointerOverGameObject()){
//perform cube animation if my button is not clicked
}
already suit my problem, i dunno, when i placed code in
if(!EventSystem.current.currentSelectedGameObject.name.Equals("name of your button"))
not resulting perform animation.
thank you..
That block was a precaution for preventing your code not to work in case of pressing other buttons rather than your button. $$anonymous$$aybe you wrote "name of your button" wrong cause it's not the text of your button, it must be the gameObject name of your button. But using this is up to you ofc.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Scripting button functionality inside class with created object's method 1 Answer
UI Decreasing Timer Bar Not Executing Print? 1 Answer
UI text showing money 2 Answers