왜 이렇게 더럽게 코딩을 하냐면 ......

 

전 초보니까요 :D

 

우선 확대 축소가 잘 되긴 합니다.

(처음 시작때 살짝 튀는 현상이 있긴 하지만.. 가끔이니....)

 

간단하게 설명하자면

마우스가 우측으로 이동한지 왼쪽으로 이동한지 확인 후

확대 축소를 결정.

 

물체와 카메라의 거리가 100이 넘거나 20보다 작으면 작은 값으로 이동

 

 

 

 

xDeg = Vector3.Angle(Vector3.right, transform.right);
distance = camera.fieldOfView;

 

 

 if (Input.GetMouseButtonDown(1))
        {
            xDeg += Input.GetAxis("Mouse X") * 10 * 0.02f;
            distance -= Input.GetAxis("Mouse X") * sensitivityDistance;

            if (xDeg > 0)
                zoom_k = true;
            else
                zoom_k = false;
            
            zoom_on = true;

        }

        if (Input.GetMouseButtonUp(1))
            zoom_on = false;

        if (zoom_on)
        {
            if (distance <= 100 && distance >= 20)
            {
                if (zoom_k)
                {
                    xDeg -= Time.deltaTime;
                    distance -= 2;
                }
                else
                {
                    xDeg += Time.deltaTime;
                    distance += 2;
                }
            }

            if (distance > 100)
            {
                if (zoom_k)
                {
                    xDeg -= Time.deltaTime;
                    distance -= 2f;
                }
                else
                {
                    xDeg += Time.deltaTime;
                    distance += 0.05f;
                }
            }
            else if (distance < 20)
            {
                if (zoom_k)
                {
                    xDeg -= Time.deltaTime;
                    distance -= 0.05f;
                }
                else
                {
                    xDeg += Time.deltaTime;
                    distance += 2f;
                }
            }

            Camera.main.fieldOfView = Mathf.Lerp(camera.fieldOfView, distance, Time.deltaTime * 5);

        }

'Programmer의 텅빈 공간 > Unity3D' 카테고리의 다른 글

유니티 창 여러개 띄우기  (0) 2014.05.06
더블 터치로 zoom 1  (0) 2014.05.06
패키지 사용할 때  (0) 2014.05.06
NGUI 참고 사이트  (0) 2014.05.06
Unity 한글 폰트 적용  (0) 2014.05.06

+ Recent posts