U
U
Uncle Bogdan2021-10-04 14:39:45
Unity
Uncle Bogdan, 2021-10-04 14:39:45

How to make a finger touch registration area?

There is this code:

The code
private void Touches()
    {
        if (Input.touchCount == 1)
        {
            foreach (Touch touch in Input.touches)
            {
                switch (touch.phase)
                {
                    case TouchPhase.Began:

                        if (_touchId == 0)
                        {
                            _touchId = touch.fingerId;
                        }

                        break;

                    case TouchPhase.Moved:

                        var delta = Mathf.Clamp(touch.deltaPosition.x, -_sensitivityLimiter, _sensitivityLimiter);

                        _velosity += _sensitivity * delta * transform.right;

                        break;

                    case TouchPhase.Canceled:
                    case TouchPhase.Ended:

                        transform.eulerAngles = new Vector3(0, 0, 0);

                        _touchId = 0;

                        break;
                }
            }
        }
    }


It registers a touch and checks the movement of the finger to the right and left. But this code works in full screen. Do you want the touch to be registered only in a certain area of ​​the screen?

6 is the registration area

615ae7f59fc0c960905671.png

Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Polishchuk, 2021-10-05
@motkot

Create UI > Button, stretch as needed, hide the image.
Or I do through the picture. I create an Image and attach an Event Trigger to it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question