유니티 러닝 쪽을 참고하는게 빠를듯!
https://learn.unity.com/tutorial/touch-input-for-mobile-scripting-1#5cf1ffb5edbc2a4ef4fb2e3a
EventSystem.current.IsPointerOverGameObject() == true 에서 리턴해주면
유아이 위에서는 작동안하게 할 수 있다.
using UnityEngine;
public class TouchCameraControl : MonoBehaviour
{
public RectTransform rect;
private Vector2 delta;
void Update()
{
//if (EventSystem.current.IsPointerOverGameObject() == true)
// return;
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
float x = rect.localPosition.x + touchDeltaPosition.x * 3f;
float y = rect.localPosition.y + touchDeltaPosition.y * 3f;
x = Mathf.Clamp(x, -1050f, 900f);
y = Mathf.Clamp(y, -1400, 1900f);
//rect.localPosition = new Vector3(x, y, 0);
rect.localPosition = Vector3.Lerp(rect.localPosition, new Vector3(x, y, 0), Time.deltaTime * 10);
}
if (Input.touchCount == 2 )
{
// Store both touches.
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
// Find the position in the previous frame of each touch.
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
// Find the magnitude of the vector (the distance) between the touches in each frame.
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
// Find the difference in the distances between each frame.
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
float localScale = rect.localScale.x - deltaMagnitudeDiff * Time.deltaTime * 0.1f;
localScale = Mathf.Clamp(localScale, 1.46f, 3f);
//rect.localScale = new Vector3(localScale, localScale, rect.localScale.z);
rect.localScale = Vector3.Lerp(rect.localScale, new Vector3(localScale, localScale, localScale), Time.deltaTime * 10);
}
}
}
# 추가 : Panning만 하는 스크립트
using UnityEngine;
using UnityEngine.EventSystems;
public class SwipeInputCtrl : MonoBehaviour, IBeginDragHandler, IDragHandler
{
public Transform targetObjTrans;
private Vector3 lastPosition;
#region 드래그
void IBeginDragHandler.OnBeginDrag(PointerEventData eventData)
{
lastPosition = eventData.position;
}
void IDragHandler.OnDrag(PointerEventData eventData)
{
Vector3 currentPosition = eventData.position;
Vector3 deltaPosition = (currentPosition - lastPosition);
lastPosition = currentPosition;
targetObjTrans.Translate(deltaPosition);
}
#endregion
}
'🌍 Unity > 유니티 프로그래밍' 카테고리의 다른 글
Touch Ray로 3d오브젝트 선택하기 (0) | 2018.06.11 |
---|---|
텍스트 타이핑 효과 (0) | 2018.06.08 |
RectTransform position 접근 (0) | 2018.05.16 |
유니티 텍스트 파일 StreamingAssets 폴더에 입출력 (0) | 2018.03.30 |
UV 스크롤러 (0) | 2016.11.27 |