- zoomInOut
```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class zoomInOut : MonoBehaviour {
Camera mainCamera;
float touchesPrevPosDifference, touchesCurPosDifference, zoomModifier;
Vector2 firstTouchPrevPos, secondTouchPrevPos;
[SerializeField]
float zoomModifierSpeed = 0.1f;
// Use this for initialization
void Start () {
mainCamera = GetComponent<Camera> ();
}
// Update is called once per frame
void Update () {
if (Input.touchCount == 2) {
Touch firstTouch = Input.GetTouch (0);
Touch secondTouch = Input.GetTouch (1);
firstTouchPrevPos = firstTouch.position - firstTouch.deltaPosition;
secondTouchPrevPos = secondTouch.position - secondTouch.deltaPosition;
touchesPrevPosDifference = (firstTouchPrevPos - secondTouchPrevPos).magnitude;
touchesCurPosDifference = (firstTouch.position - secondTouch.position).magnitude;
zoomModifier = (firstTouch.deltaPosition - secondTouch.deltaPosition).magnitude * zoomModifierSpeed;
if (touchesPrevPosDifference > touchesCurPosDifference)
mainCamera.orthographicSize += zoomModifier;
if (touchesPrevPosDifference < touchesCurPosDifference)
mainCamera.orthographicSize -= zoomModifier;
}
mainCamera.orthographicSize = Mathf.Clamp (mainCamera.orthographicSize, 2f, 10f);
}
}
```
'tech > metaverse' 카테고리의 다른 글
21/08/19 Unity load data from server in JSON format ,load images (0) | 2021.08.19 |
---|---|
21/08/18 이거 하나면 모바일 해상도 걱정 끝! 16:9 고정해상도 만들기 (0) | 2021.08.18 |
21/08/17 2D Game Development (0) | 2021.08.17 |
21/08/17 Tilemap System - Unity (0) | 2021.08.17 |
21/08/17 유니티 2D 기초 (Unity 2D Basic) - 고박사 (0) | 2021.08.17 |