How do I go about this functionality: When a user taps and still holds onto a UI button, a GameObject will be set active, when they release the UI button, the GameObject will be deactivated.
-
\$\begingroup\$ Should a user hold the button for some time to activate GameObject or it's immediate? What should happen if the user moves his finger away from the button but still touching the screen? \$\endgroup\$– trollingcharJul 3, 2019 at 8:41
-
\$\begingroup\$ What have you tried? At what step did it fail? \$\endgroup\$– Tom TsagkatosJul 3, 2019 at 8:42
-
\$\begingroup\$ Presumably you tried using a PointerUp event to detect the moment of release? \$\endgroup\$– DMGregory ♦Jul 3, 2019 at 10:53
-
\$\begingroup\$ Actually, I figured it out through the event data. \$\endgroup\$– GozmetaiemaxJul 3, 2019 at 14:37
-
\$\begingroup\$ If you've solved your problem, remember to post your solution as an Answer below. \$\endgroup\$– DMGregory ♦Jul 3, 2019 at 16:05
1 Answer
Add the event trigger component, then add the pointerDown and pointerUp events, then create a script with 2 public methods of type void, and respectively reference them in the pointerDown and pointerUp events, one should contain the functionality that will happen if the user presses and holds(attached to the pointerDown event), while the other should contain the functionality that will happen if the user lets go of the button(attached to the pointerUp event).