L
L
Lesh482020-03-16 14:15:12
User interface
Lesh48, 2020-03-16 14:15:12

(unity) how to track touch in a certain area of ​​the screen (on a collider or something like that)?

I want that when touching in a certain area (ui), a part of the code (the first phase of touch) works on the screen, since each has a different screen dimension, I want this area to be, for example, a collider, the problem is that I did not find any way this is tracked apart from checking by pixels. Please help, who knows!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2020-03-16
@Lesh48

tell good people what you mean by "the first phase of touch"
to track the touch of a collider hanging on an object in the scene (in world, non-screen coordinates and without stipulating any "somehow to bind it to the upper right corner of the screen")
is quite simple, as in to me the most flexible and extensible way is through rays:
- determine where the player’s finger is now, the screen coordinates of the wheelbarrow or mouse (which is essentially the same)
- we turn the touch screen coordinates into world ones using the current camera in the scene ( here in the documentation we look and read )
- launch a beam, it will be more convenient with a layer mask to check if there is a collider under the finger on the layer we need ( here's some more documentation )
- if our beam hit the collider, then we have a link to it, we can check the tag / name or search for the necessary script marker on it (here it depends on why you need it)
- and now we are sure that hit the collider and this is the desired collider - we perform the action.
Voila.
I hope it helps. good luck)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question