전에 찾은 예제 코드를 이용해서 원하는 형태로 바꾼 코드 !
실제 제가 안드로이드에서 실행해본 결과 괜찮게 동작하네요 :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);
}
}
}
}
'Programmer의 텅빈 공간 > Unity3D' 카테고리의 다른 글
GUI 버튼 사용시 버튼을 누르고 있을 때 동작하게 만들기 (0) | 2014.05.06 |
---|---|
유니티 창 여러개 띄우기 (0) | 2014.05.06 |
더블 터치로 zoom 1 (0) | 2014.05.06 |
마우스 우 클릭으로 확대 축소 하기 (0) | 2014.05.06 |
패키지 사용할 때 (0) | 2014.05.06 |