码迷,mamicode.com
首页 > 编程语言 > 详细

Unity UGUI在鼠标位置不同时 图片浮动效果

时间:2016-04-05 00:45:23      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:

 1 /// <summary>
 2 /// 在鼠标位置不同时 图片浮动效果
 3 /// </summary>
 4 public class TiltWindow : MonoBehaviour
 5 {
 6     public Vector2 range = new Vector2(5f, 3f);
 7 
 8     Transform mTrans;
 9     Quaternion mStart;
10     Vector2 mRot = Vector2.zero;
11 
12     void Start ()
13     {
14         mTrans = transform;
15         mStart = mTrans.localRotation;
16     }
17 
18     void Update ()
19     {
20         Vector3 pos = Input.mousePosition;
21 
22         float halfWidth = Screen.width * 0.5f;
23         float halfHeight = Screen.height * 0.5f;
24         float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f);
25         float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f);
26         mRot = Vector2.Lerp(mRot, new Vector2(x, y), Time.deltaTime * 5f);
27 
28         mTrans.localRotation = mStart * Quaternion.Euler(-mRot.y * range.y, mRot.x * range.x, 0f);
29     }
30 }

 

Unity UGUI在鼠标位置不同时 图片浮动效果

标签:

原文地址:http://www.cnblogs.com/redUnity/p/5353300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!