전에 찾은 예제 코드를 이용해서 원하는 형태로 바꾼 코드 !

 

실제 제가 안드로이드에서 실행해본 결과 괜찮게 동작하네요 :D

 

최대로 커질때와 최소일때 제한을 둔 형태로 부드럽게 확대 축소 되는 코드입니당 :D

 

 

  void touchZoom()
    {
        if (Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved)
        {

            float touchDelta = 0.0F;
            Vector2 prevDist = new Vector2(0, 0);
            Vector2 curDist = new Vector2(0, 0);

            curDist = Input.GetTouch(0).position - Input.GetTouch(1).position;
            //current distance between finger touches
            prevDist = ((Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition) - (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition));
            //difference in previous locations using delta positions
            touchDelta = curDist.magnitude - prevDist.magnitude;

            distance_two -= touchDelta;
            if (distance_two > 100)
                distance_two = 100;
            else if (distance_two < 20)
                distance_two = 20;
            
           

            if (distance_two < 100 && distance_two >20)
            {
                if ((touchDelta < 0)) //
                {
                    Camera.main.fieldOfView = Mathf.Lerp(camera.fieldOfView, distance_two, Time.deltaTime * 5);
                }

                if ((touchDelta > 0))
                {
                    Camera.main.fieldOfView = Mathf.Lerp(camera.fieldOfView, distance_two, Time.deltaTime * 5);
                }
            }

        }

    }

+ Recent posts