Search code examples
c#unity-game-enginetouch

Converting TUIO Touch Inputs to UNITY touches


What would the following function look like instead of using TUIO touches with UNITY touches?

/// Fingers touch.
/// </summary>
private void FingerTouch ()
{
    var beganTouches = from Tuio.Touch t in TuioTrackingComponent.Touches.Values
        where t.Status == TouchStatus.Began
            select t;

    // Raycast and attached springs to the hit objects
    foreach (Tuio.Touch t in beganTouches) {    
        if (Physics.Raycast (Camera.main.ScreenPointToRay (new Vector3 (t.TouchPoint.x, t.TouchPoint.y, 0f)), out hit)) {
            if (hit.collider != null && hit.transform.gameObject.CompareTag ("FishCollider")) {
                touchedFishes.Add (t.TouchId, hit.transform.parent.gameObject);
                isHolding = true;
            }
        }
        MoveFish (t);
    }
}

Solution

  • It is very similar. Take a look at the documentation:

    foreach (Touch touch in Input.touches)
    {
        if (touch.phase == TouchPhase.Began)
        {
            if (Physics.Raycast(Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0f)), out hit))
            {
                if (hit.collider != null && hit.transform.gameObject.CompareTag("FishCollider"))
                {
                    touchedFishes.Add(touch.fingerId, hit.transform.parent.gameObject);
                    isHolding = true;
                }
            }
            MoveFish(touch);
        }
    }