Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

MacOS - Handling two fingers pinching (zoom in/out)

Discussion in 'Editor & General Support' started by moreirac, Apr 20, 2018.

  1. moreirac

    moreirac

    Joined:
    Oct 9, 2017
    Posts:
    5
    Hi,

    I want the user to be able to zoom in/out in the Unity scene just like he would do in Google Maps for instance.

    On MacOS this is done by simply touching the fingers and pinching in or out.

    I tried monitoring Input events but none has returned me anything in Unity. I tried the GetAxis(Mouse ScrollWheel), Input.inputString, Input. mouseScrollDelta, and lots of other methods available under Input class, but none returns me anything.

    How can I handle that MacOS pinching feature that is used in the TrackPad?

    Thanks,
    Caio
     
  2. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    I've not done in in macOS, but I have in iOS, hopefully it is the same.

    Store the distance between the fingers when 2 touches started. Compare that to the current distance between the fingers and scale appropriately.
     
  3. moreirac

    moreirac

    Joined:
    Oct 9, 2017
    Posts:
    5
    So none of the Input.*touch* fields has anything when I use the two fingers in the touch to do the smart zoom of Mac.
     
  4. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    Try this to see if you get anything on the Console:

    if (Input.touchCount > 0)
    Debug.Log(Input.GetTouch(0).position);
     
  5. moreirac

    moreirac

    Joined:
    Oct 9, 2017
    Posts:
    5