赞
踩
PlayerSetting里设置 File——BuildSetting——PlayerSetting——Player——Default Cursor、Cursor Hotspot

代码设置如果用只是想改变一下光标,用Start里语句就可以了;如果想鼠标按下时,光标切换成另一张图片,用Update里的语句即可。
public class CursorChange : MonoBehaviour { public Texture2D cursorTexture_Normal; public Texture2D cursorTexture_MouseDown; //public float x; //public float y; void Start() { Cursor.SetCursor(cursorTexture_Normal, Vector2.zero, CursorMode.Auto); } void Update() { if(Input.GetMouseButton(0)) { Cursor.SetCursor(cursorTexture_MouseDown, Vector2.zero, CursorMode.Auto); } else { Cursor.SetCursor(cursorTexture_Normal, Vector2.zero, CursorMode.Auto); } } }
以上两法,直接赋图片,常常出现点击不精确的情况——可以看到它们都有偏移量的设置(代码中用二维向量Vector2设置)
光标的有效点,是光标尖端,而下面两张图,滴管起作用的点是左下角吸口,靶子起作用的点是靶心


Texture图片是用GUI坐标系绘制的,左上角是图片(0,0)原点,向下Y值增加,向右X值增加。

该函数的意思是,把光标放到图片的什么位置
滴管得把光标放到图片的左下角,假设滴管图片尺寸是260x330,那么光标在图片中的坐标就是(0,330)——吸口处new Vector2(0,330)

靶子得把光标放到图片的正中心,假设靶子图片的尺寸是50x50,那么光标在图片中的坐标就是(25,25)——靶心处new Vector2(25,25)

PlayerSetting里的偏移原理,和代码中是相同的

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。