1 using UnityEngine;
2
3 public
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         Vector3 pos = Input.mousePosition;
20
21         
float halfWidth = Screen.width * 0.5f;
22         
float halfHeight = Screen.height * 0.5f;
23         
float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f);
24         
float 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 }


Gõ tìm kiếm nhanh...