Creating a 2D sprite with Trigger Events?
Hi there, have been sitting at this problem the whole day, and I need some help from you guys.
Basically in my have multiple sprites which need to have Event Triggers. I know they are easy to implement and I have played around with applying Event Triggers to buttons, but I have recognized several bugs that appeared, so I cannot work with buttons.
The idea is when sprite is pressed longer (pressed on hold) I would like to lamp to work in my, but when it is released it would turn off.
So far I have added Collider, Rigidbody and Event Trigger to my sprite, but nothing seems to be working. I cannot even Debug a message from the method. If I do the same thing with UI Button not the Sprite, then everything works finem, but in my case I need Sprite to work.
Any ideas on how to fix my problem?
Answer by ilyavitek · Aug 20, 2018 at 08:08 AM
Hi @Alberts !
Here is part of the documentation that can help you: https://docs.unity3d.com/Manual/EventSystem.html
As an answer I think you need to use one of these components attached to the main camera:
"Physics 2D Raycaster" - Used for 2D physics elements
or
"Physics Raycaster" - Used for 3D physics elements
Which of them to use you can choose by what type of colliders you use (2d or regular one).
Answer by dginovker · Dec 21, 2020 at 02:29 AM
Not to necrobump, but I struggled with this and found a pretty simple solution (Unity 2019):
CAMERA:
Add Physics Raycaster
2D SPRITE
Add Event Trigger and Box Collider
(Then add your Pointer Click or w/e to your Event Trigger)