思路:使用Screen.showCursor = false; 将鼠标光标隐藏。然后用其它图片根随鼠标移动,模拟鼠标指针。
参考代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
var
myCursor:Texture2D;
var
cursorSizeX:
int
=
32;//
set to width of your cursor texture
var
cursorSizeY:
int
=
32;//
set to height of your cursor texture
var
condition
=
true;
function
OnMouseEnter(){
condition
=
false;
Screen.showCursor
=
false;
}
function
OnMouseExit(){
condition
=
true;
Screen.showCursor
=
true;
}
function
OnGUI(){
if(!condition){
GUI.DrawTexture
(Rect(Input.mousePosition.x-cursorSizeX/2
+
cursorSizeX/2,
(Screen.height-Input.mousePosition.y)-cursorSizeY/2
+
cursorSizeY/2,
cursorSizeX,
cursorSizeY),myCursor);
}
}
|
本文介绍如何在Unity中隐藏默认的鼠标光标,并使用自定义图片作为鼠标指针。通过检测鼠标进入和离开事件来控制显示效果,提供了一段示例代码实现这一功能。
758

被折叠的 条评论
为什么被折叠?



