本文共 1181 字,大约阅读时间需要 3 分钟。
记录:前段时间遇到一个需求,就是打包出来要在某种情况下鼠标的样子要改变成想要的样式。
详细代码如下public Texture2D[] hand;//小指图标 ////// 鼠标变成小手图标的切换 /// public void ChangeXiaoShou(bool isTrue) { IsEnter = isTrue; int index; index = Input.GetMouseButton(0) ? 0 : 1; if (isTrue) Cursor.SetCursor(hand[index], Vector2.zero, CursorMode.Auto);//变成手 else Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);//变回来 }
这样就可以实现了,但是后来打包web的时候发现还是没办法实现这个效果。目前只试了pc端可以这样弄。
web端的话,只需要把这个判断放在OnGUI里面就可以用了。
bool IsEnter; private void OnGUI() { if (IsEnter) { int index = Input.GetMouseButton(0) ? 0 : 1; GUI.DrawTexture(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 40, 40), hand[index]); } } public Texture2D[] hand;//小指图标 ////// 鼠标变成小手图标的切换 /// public void ChangeXiaoShou(bool isTrue) { IsEnter = isTrue; int index; index = Input.GetMouseButton(0) ? 0 : 1; if (isTrue) Cursor.visible = false;//变成手 else Cursor.visible = true;//变回来 }
究其原因的话,我这边还是没找到是因为什么,个人感觉可能是没有权限吧。因为我的图标资源位置是随便放的。
如有不对,欢迎指正!转载地址:http://kfccz.baihongyu.com/