Skip to content

Touch Input

VirtueSky edited this page Jul 25, 2024 · 2 revisions

What

  • Touch handling support tool for unity games (use Touch Phase)

Use

  • Attach TouchInputManager to the scene and click create InputEvent

Unity_dDVXcpbXeX

  • Demo script uses TouchInputManager (move gameobject cube by touch or mouse)
    [SerializeField] private InputEventTouchBegin touchBeginEvent;
    [SerializeField] private InputEventTouchMove touchMoveEvent;
    [SerializeField] private InputEventTouchEnd touchEndEvent;
    [SerializeField] private InputEventTouchStationary touchStationary;
    [SerializeField] private InputEventTouchCancel touchCancel;

    public GameObject cube;
    public Camera camera;

    private void OnEnable()
    {
        touchBeginEvent.AddListener(StartTouch);
        touchMoveEvent.AddListener(MoveTouch);
        touchEndEvent.AddListener(EndTouch);
        touchStationary.AddListener(StationTouch);
        touchCancel.AddListener(CancelTouch);
    }

    #region Touch

    private void StartTouch(Vector3 v3)
    {
        Debug.Log($"start: {v3}");
    }

    private void MoveTouch(Vector3 v3)
    {
        Debug.Log($"move: {v3}");
        cube.transform.SetPositionXY(camera.ScreenToWorldPoint(v3));
    }

    private void EndTouch(Vector3 v3)
    {
        Debug.Log($"end: {v3}");
    }

    private void StationTouch(Vector3 v3)
    {
        Debug.Log($"station: {v3}");
    }

    private void CancelTouch(Vector3 v3)
    {
        Debug.Log($"cancel: {v3}");
    }

    #endregion
Clone this wiki locally