From 115f77bda0246a00f6e17469685c67746bdbd29d Mon Sep 17 00:00:00 2001 From: nirav Date: Sat, 12 Dec 2020 07:18:36 +0000 Subject: Initial commit --- Assets/SampleUI/Scripts/TiltWindow.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 Assets/SampleUI/Scripts/TiltWindow.cs (limited to 'Assets/SampleUI/Scripts/TiltWindow.cs') diff --git a/Assets/SampleUI/Scripts/TiltWindow.cs b/Assets/SampleUI/Scripts/TiltWindow.cs new file mode 100755 index 0000000..8325504 --- /dev/null +++ b/Assets/SampleUI/Scripts/TiltWindow.cs @@ -0,0 +1,29 @@ +using UnityEngine; + +public class TiltWindow : MonoBehaviour +{ + public Vector2 range = new Vector2(5f, 3f); + + Transform mTrans; + Quaternion mStart; + Vector2 mRot = Vector2.zero; + + void Start () + { + mTrans = transform; + mStart = mTrans.localRotation; + } + + void Update () + { + Vector3 pos = Input.mousePosition; + + float halfWidth = Screen.width * 0.5f; + float halfHeight = Screen.height * 0.5f; + float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f); + float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f); + mRot = Vector2.Lerp(mRot, new Vector2(x, y), Time.deltaTime * 5f); + + mTrans.localRotation = mStart * Quaternion.Euler(-mRot.y * range.y, mRot.x * range.x, 0f); + } +} -- cgit v1.2.3