unity3d - Detect mouse clicked on GUI -
i got problem in project. want know mouse cliked happend on gui or on game object. have tried showing null reference exception
eventsystem eventsystem = eventsystem.current; if (eventsystem.ispointerovergameobject()) debug.log("left click on gui element");
how detect?? there event available or else?
ispointerovergameobject()
broken on mobile , corner cases. rolled our own our project , works champ on platforms we've thrown at.
private bool ispointeroveruiobject() { pointereventdata eventdatacurrentposition = new pointereventdata(eventsystem.current); eventdatacurrentposition.position = new vector2(input.mouseposition.x, input.mouseposition.y); list<raycastresult> results = new list<raycastresult>(); eventsystem.current.raycastall(eventdatacurrentposition, results); return results.count > 0; }
Comments
Post a Comment