- Home /
Help, Use event system IPointerClickHandler
is unity event system (OnPointerClick etc..) is not work on gameobject (not a UI GameObject child of Canvas) ??
i have a game object with transform and sprite renderer i ineed to IPointerClickHandler
Answer by donutLaserDev · Jul 19, 2018 at 06:42 AM
Firstly, you have to have an Event System game object in the scene in order for these handlers to work. Then you can add an Event Trigger component to the game object, select the PointerClickHandler and simply specify what method should be called upon the click or you can implement the interface yourself in the script. Edit: also, there should be a Physics Raycaster or Physics Raycaster 2D component on the Main Camera (depending on what game are you trying to do, 2D or 3D) and the object you are trying to click on should a collider.
thank for response this is not work for gameobject non child of canvas
Oh yeah, sorry, forgot to mention. You have to add a Physics Raycaster 2D component to the $$anonymous$$ain Camera and add a Box Collider 2D to the sprite.