虽然很晚了,还是忍不住想更一下~
这次是关于修改鼠标指针的~
相信大家都想让自己的程序有一个自拟定的个性鼠标指针吧,其实实现方法简单到爆,主体思想就是将系统默认的鼠标指针给屏蔽掉,然后换一张图片实时更新到当前鼠标位置,当然,图片是可以自己设的哦~
当前鼠标位置可以通过input.mousePosition获取到~
以下是代码:
using UnityEngine;
using System.Collections;
public class Cursor_CTRL : MonoBehaviour
{
public bool IsShow_cursor = false;
public Texture cursor_pen, cursor_rubber, cursor_nomal;
public int tag_cursor = 0;//记录当前鼠标类型,0代表正常模式,1代表pen,2代表rubber
Vector3 mousePositionNow;
// Use this for initialization
void Start ()
{
Screen.showCursor = IsShow_cursor;
}
// Update is called once per frame
void Update ()
{
}
void OnGUI()
{
mousePositionNow = Input.mousePosition;
if(tag_cursor==0)
{
GUI.DrawTexture (new Rect(mousePositionNow.x-10f, Screen.height-mousePositionNow.y-10f, cursor_nomal.width*0.1f, cursor_nomal.height*0.1f), cursor_nomal);
}
else if(tag_cursor == 1)
{
GUI.DrawTexture (new Rect(mousePositionNow.x, Screen.height-mousePositionNow.y, cursor_pen.width, cursor_pen.height), cursor_pen);
}
else
{
GUI.DrawTexture (new Rect(mousePositionNow.x, Screen.height-mousePositionNow.y, cursor_rubber.width, cursor_rubber.height), cursor_rubber);
}
}
}
上一段代码提供了三种鼠标指针样式,当然图片是需要大家在脚本完成后自行拖入的~
然后运行效果如下图:

这次是关于修改鼠标指针的~
相信大家都想让自己的程序有一个自拟定的个性鼠标指针吧,其实实现方法简单到爆,主体思想就是将系统默认的鼠标指针给屏蔽掉,然后换一张图片实时更新到当前鼠标位置,当然,图片是可以自己设的哦~
当前鼠标位置可以通过input.mousePosition获取到~
以下是代码:
using UnityEngine;
using System.Collections;
public class Cursor_CTRL : MonoBehaviour
{
public bool IsShow_cursor = false;
public Texture cursor_pen, cursor_rubber, cursor_nomal;
public int tag_cursor = 0;//记录当前鼠标类型,0代表正常模式,1代表pen,2代表rubber
Vector3 mousePositionNow;
// Use this for initialization
void Start ()
{
Screen.showCursor = IsShow_cursor;
}
// Update is called once per frame
void Update ()
{
}
void OnGUI()
{
mousePositionNow = Input.mousePosition;
if(tag_cursor==0)
{
GUI.DrawTexture (new Rect(mousePositionNow.x-10f, Screen.height-mousePositionNow.y-10f, cursor_nomal.width*0.1f, cursor_nomal.height*0.1f), cursor_nomal);
}
else if(tag_cursor == 1)
{
GUI.DrawTexture (new Rect(mousePositionNow.x, Screen.height-mousePositionNow.y, cursor_pen.width, cursor_pen.height), cursor_pen);
}
else
{
GUI.DrawTexture (new Rect(mousePositionNow.x, Screen.height-mousePositionNow.y, cursor_rubber.width, cursor_rubber.height), cursor_rubber);
}
}
}
上一段代码提供了三种鼠标指针样式,当然图片是需要大家在脚本完成后自行拖入的~
然后运行效果如下图:
