반응형
- 코드 작성
using UnityEngine;
public class CameraZoom : MonoBehaviour
{
public float zoomSpeed = 0.1f;
public float minZoom = 1f;
public float maxZoom = 10f;
private float currentZoom = 1f;
void Update()
{
if (Input.touchCount == 2)
{
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
currentZoom += deltaMagnitudeDiff * zoomSpeed;
currentZoom = Mathf.Clamp(currentZoom, minZoom, maxZoom);
transform.position += transform.forward * deltaMagnitudeDiff * zoomSpeed;
transform.localScale = new Vector3(currentZoom, currentZoom, currentZoom);
}
}
}
반응형