c# - Detecting long press with Unity with distance -
i looking solution detect long press , tap, i'm kind of lost, know has deltaposition
or deltatime
.
can explain me? i'm new unity.
it's dragging button, press button couple of frames, , if drag couple of pixels enter in drag_state
, if tap it go tapped_state
.
notes :
i have detect distance too
i can't use "touch" functions, need simulate mouse
when detect press, store position. on following frames, check if position has changed:
vector3 position; void update(){ if(input.getmousebuttondown(0)) { this.position = input.mouseposition;} else if(input.getmousebutton(0)){ float distance = vector3.distance(this.position, input.mouseposition); } else if(input.getmousebuttonup(0)) { this.position = vector3.zero } }
so on enter, record position, when user presses down button. nothing else happens on frame.
next frame, if user keeps pressing, compare previous (initial) position , current one. should pass distance wherever needed. if distance small enough, discard drag or ignore it.
finally, when user releases button, reset 0. may want reset negative value make sure value not usable value (tho 0 unlikely not impossible).
Comments
Post a Comment