8 public class TiltWindow : MonoBehaviour, IDragHandler
10 public Vector2
range =
new Vector2(5f, 3f);
12 private Transform mTrans;
13 private Quaternion mStart;
14 private Vector2 mRot = Vector2.zero;
15 private Vector2 m_screenPos;
21 mStart = mTrans.localRotation;
26 Vector3 pos = m_screenPos;
28 float halfWidth = Screen.width * 0.5f;
29 float halfHeight = Screen.height * 0.5f;
30 float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f);
31 float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f);
32 mRot = Vector2.Lerp(mRot,
new Vector2(x, y), Time.deltaTime * 5f);
34 mTrans.localRotation = mStart * Quaternion.Euler(-mRot.y *
range.y, mRot.x *
range.x, 0f);
38 public void OnDrag(PointerEventData eventData)
40 m_screenPos = eventData.position;
void OnDrag(PointerEventData eventData)
Credit Erdener Gonenc - @PixelEnvision.