# Lean Touch

## What for

Handle user input touches by events:

```csharp
public class InputPrinter : MonoBehaviour {

    private void OnEnable() {
        LeanTouch.OnFingerUpdate += UpdateMove;
        LeanTouch.OnFingerDown += OnTouchDown;
        LeanTouch.OnFingerUp += OnTouchUp;
    }

    private void OnDisable() {
        LeanTouch.OnFingerUpdate -= UpdateMove;
        LeanTouch.OnFingerDown -= OnTouchDown;
        LeanTouch.OnFingerUp -= OnTouchUp;
    }

    private void OnTouchUp(LeanFinger finger) {
        print($"Last touch was in {finger.ScreenPosition}.\n" +
            $"Touch down and up positions delta = {finger.ScreenPosition - finger.StartScreenPosition}");
    }

    private void UpdateMove(LeanFinger finger) {
        print($"Move delta from touch down pos: {finger.ScreenPosition - finger.StartScreenPosition}\n" +
            $"Move delta between frames: {finger.ScreenPosition - finger.LastScreenPosition}");
    }

    private void OnTouchDown(LeanFinger finger) {
        print($"Touch down in {finger.ScreenPosition}");
    }
}
```

{% hint style="danger" %}
LeanTouch events are Action type. So you need to unsubscribe them in OnDestroy on OnDisable and avoid null references after scene change or object destroyed.
{% endhint %}

## Basic setup

Add LeanTouch prefab to your scene - that's it.

We use Lean Touch for our custom [**Joystick**](https://reddycat.gitbook.io/base-project-cube-doc/fundamentals/other-modules/joystick). You can find example how it's implemented in **Assets/\_Examples/PlayerInput/Joystick/Joystick.scene**

We use this class in TouchRaycaster ([**RaycastManager**](https://reddycat.gitbook.io/base-project-cube-doc/fundamentals/singletons/raycastmanager) section).
