Tanoda
HSVPicker/Other/TiltWindow.cs
Go to the documentation of this file.
1using UnityEngine;
2
3public class TiltWindow : MonoBehaviour
4{
5 public Vector2 range = new Vector2(5f, 3f);
6
7 Transform mTrans;
8 Quaternion mStart;
9 Vector2 mRot = Vector2.zero;
10
11 void Start()
12 {
13 mTrans = transform;
14 mStart = mTrans.localRotation;
15 }
16
17 void Update()
18 {
19 var pos = Input.mousePosition;
20
21 var halfWidth = Screen.width * 0.5f;
22 var halfHeight = Screen.height * 0.5f;
23 var x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f);
24 var y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f);
25 mRot = Vector2.Lerp(mRot, new Vector2(x, y), Time.deltaTime * 5f);
26
27 mTrans.localRotation = mStart * Quaternion.Euler(-mRot.y * range.y, mRot.x * range.x, 0f);
28 }
29}