首页 > 其他 > 详细

Unity3d之个性化鼠标

时间:2014-09-11 23:38:22      阅读:300      评论:0      收藏:0      [点我收藏+]

代码实例:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class CursorController : MonoBehaviour
 5 {
 6     /// <summary>
 7     /// 一般鼠标样式
 8     /// </summary>
 9     public Texture2D cursorMouseNormol;
10     /// <summary>
11     /// 单击鼠标样式
12     /// </summary>
13     public Texture2D cursorMouseClick;
14 
15     public float cursorWidth;
16     public float cursorHeight;
17     /// <summary>
18     /// 是否按下鼠标
19     /// </summary>
20     private bool isMouseClick = false;
21     // Use this for initialization
22     void Start()
23     {
24         //关闭系统默认鼠标显示
25         Screen.showCursor = false;
26         cursorWidth = cursorMouseNormol.width;
27         cursorHeight = cursorMouseNormol.height;
28     }
29 
30     // Update is called once per frame
31     void Update()
32     {
33         //鼠标左键单击切换鼠标样式
34         if (Input.GetMouseButtonDown(0))
35         {
36             isMouseClick = true;
37         }
38         else if (Input.GetMouseButtonUp(0))
39         {
40             isMouseClick = false;
41         }
42     }
43 
44     void OnGUI()
45     {
46         if (isMouseClick)
47         {
48             GUI.DrawTexture(new Rect(Input.mousePosition.x - cursorWidth / 2f, Screen.height - Input.mousePosition.y - cursorHeight / 2f, cursorWidth, cursorHeight), cursorMouseClick);
49         }
50         else
51         {
52             GUI.DrawTexture(new Rect(Input.mousePosition.x - cursorWidth / 2f, Screen.height - Input.mousePosition.y - cursorHeight / 2f, cursorWidth, cursorHeight), cursorMouseNormol);
53         }
54     }
55 }

PS:屏幕坐标系:左上角为原点

       鼠标坐标系:左下角为原点

Unity3d之个性化鼠标

原文:http://www.cnblogs.com/Moranyouqing/p/3967412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!