Search Unity

Pinch to Scale script

Discussion in 'Scripting' started by Vindatra14, Nov 23, 2015.

  1. Vindatra14

    Vindatra14

    Joined:
    May 8, 2015
    Posts:
    87
    can any1 tell me about code that this unity tutorial give about pinch to zoom, there's a code like camera.isOtographic, camera.ortographicSize, camera.fieldOfView. But I can't use that all, not even find at the autotext too. Can any1 explain it what that code related, or how to use that code ?? Thanks anyways
     
  2. LTK

    LTK

    Joined:
    Jul 16, 2015
    Posts:
    24
  3. Vindatra14

    Vindatra14

    Joined:
    May 8, 2015
    Posts:
    87
    yea I see that tutorial but I can't even understand camera.isOrtographic, when I try it at script there's no isOrtographic at autotext. That's why I go to here, maybe u can explain it ??
     
  4. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    isOrthographic is deprecated just use "camera.orthographic" instead.
     
  5. Vindatra14

    Vindatra14

    Joined:
    May 8, 2015
    Posts:
    87
    It still give me the same error, it's like no method for it
     
  6. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    It's not a method, its a bool Property, make it = to true for Ortographic mode or false for perspective.

    Also what are you trying to run it on, you need a Camera Object, you cant just run it on the class since its a instance member not a static memeber.
     
  7. Vindatra14

    Vindatra14

    Joined:
    May 8, 2015
    Posts:
    87
    hhmm my unity detect it change obselete API then, my script change automatically into this and this is still the same script that unity tutorial give about pinch. I'm not attach all the script I attach just the last script that change because of API. from the first if till last script.

    Code (CSharp):
    1.   if (GetComponent<Camera>())
    2.             {
    3.                 // ... change the orthographic size based on the change in distance between the touches.
    4.                 GetComponent<Camera>().orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;
    5.  
    6.                 // Make sure the orthographic size never drops below zero.
    7.                 GetComponent<Camera>().orthographicSize = Mathf.Max(GetComponent<Camera>().orthographicSize, 0.1f);
    8.             }
    9.             else
    10.             {
    11.                 // Otherwise change the field of view based on the change in distance between the touches.
    12.                 GetComponent<Camera>().fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed;
    13.  
    14.                 // Clamp the field of view to make sure it's between 0 and 180.
    15.                 GetComponent<Camera>().fieldOfView = Mathf.Clamp(GetComponent<Camera>().fieldOfView, 0.1f, 179.9f);
    16.             }
    17.         }