T
T
TheGrowww2020-06-20 14:02:10
Unity
TheGrowww, 2020-06-20 14:02:10

How to track real-time swipes in Unity?

I am making a game for android in unity, I need to track swipes in real time, for example, if I moved my finger, the object immediately turned. I tried with Mouse X, but it turns out to be sharp, for example, if I click on the corner of the screen, then it turns instantly, although I didn’t even run my finger. How can I fix this, or tell me a better method.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kenflesh, 2020-06-21
@Kenflesh

The unit has a special Touch to work with touch input. You can use Input.touches, Input.GetTouch(index) and more.
if(Input.touchCount) {
var touch = Input.GetTouch(0); and you get access to the first touch on the screen, then through touch.position you get where on the screen in pixels the click occurs and to translate this into world coordinates you need to use Camera.main.ScreenToWorldPoint(* here touch.position or its edited vector) ; All this in the conditional construction above.
You can also use plugins and more, for example, LeanTouch which can be downloaded for free in the asset store or others with the names finger / fingers and touch / touches

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question