unity5.0怎么隐藏unity 光标位置

求助!求助!新手!关于鼠标的隐藏和显示【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:74,936贴子:
求助!求助!新手!关于鼠标的隐藏和显示收藏
c#下用了Screen.showCursor=false;来隐藏,那么想要按下esc弹出菜单栏之后显示鼠标怎么做啊?
达内unity3d培训全程&实战教学&,unity3d金牌讲师授课.免费unity3d课程试听中!到达内unity3d学院学习unity3d,只需4个月速成unity3d游戏工程师.
菜单栏弹出是一个状态,触发该状态时显示鼠标
Screen.showCursor =
楼主你可以是使用Screen.lockCursor = !Screen.lockC来实现。
登录百度帐号推荐应用Unity(4)
Cusor.lockState=CusorLockMode.L&& //锁定光标不能动&&& 注:可按Esc解锁光标
Cusor.visible=false&&&//隐藏光标
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:856次
排名:千里之外2695人阅读
unity(186)
通过搜集网上鼠标光标形状改变,整理如下
1.将下面javascript代码,将它挂在任意对象上即可,然后将手形状的图片拖动面板中,这种方法比较简单,写的代码也比较少
var mouse : T
Screen.showCursor=
function Update () {
function OnGUI()
var msPos = Input.mouseP
GUI.DrawTexture(Rect(msPos.x , Screen.height-msPos.y,20,20),mouse);
效果图 如下
//原理很简单,先把鼠标光标屏蔽掉
//通过GUI来给鼠标位置放置一个贴图
注意的是:
鼠标坐标系同屏幕坐标系,屏幕的左下角是(0,0)点,向右X增加,向上Y增加
GUI的Rect区域坐标系同视口坐标系,左上角是(0,0)点,向右X增加,向下Y增加
注意坐标的变换
***************************************************************************
2.以下是c#代码,注意project面板中,要新建Resource文件夹,并且路径为Resource/Texture/Cursors/Cursor,不然加载不成功
using UnityE
using System.R
using System.C
using System.Collections.G
public class Cursorsystem : MonoBehaviour {
private TCursorState nowCursorState = TCursorState.N
private List&Texture2D& CursorTex = new List&Texture2D&();
private Rect CursorRect = new Rect();
private int cursorcount =0;
private float counttime =0.0f;
// Use this for initializationS
void Start ()&
// Update is called once per frame
void Update ()&
void OnGUI()
if(GUI.Button(new Rect(100,100,125,25),&None&))
SetCursorStyle( TCursorState.None);
if(GUI.Button(new Rect(100,125,125,25),&cCatch&))
SetCursorStyle( TCursorState.cCatch);
if(!Screen.showCursor)
if( (Time.time - counttime) & 0.3f )
counttime = Time.
cursorcount ++;
cursorcount = cursorcount%CursorTex.C
GUI.depth = 70;
CursorRect.x = Input.mousePosition.x;
CursorRect.y = Screen.height-Input.mousePosition.y;
CursorRect.width =CursorTex[cursorcount].
CursorRect.height = CursorTex[cursorcount].
GUI.DrawTexture(CursorRect,CursorTex[cursorcount]);
GUI.depth = 0;
public void SetCursorStyle(TCursorState style )
if (nowCursorState == style)
nowCursorState =
if(style == TCursorState.None)
Screen.showCursor =
CursorTex.Clear();
Screen.showCursor =
cursorcount=0;
counttime =Time.
CursorTex.Clear();
TCursorStruct cursor = (TCursorStruct)RetrieveEnum&TCursorStruct&(style);
for(int i =0; i & cursor.i++ )
Texture2D tex = (Texture2D)Resources.Load(&Texture/Cursors/Cursor&+ cursor.ID.ToString()+&_&+i.ToString(), typeof(Texture2D));
CursorTex.Add(tex);
public &T RetrieveEnum&T&(Enum value)
& & & & Type type = value.GetType();
& & & & FieldInfo fi = type.GetField(value.ToString());
& & & & T[] attrs = fi.GetCustomAttributes(typeof(T), false) as T[];
& & & & if (attrs.Length & 0)
& & & & & & return attrs[0];
& & & & return default(T);
public class TCursorStruct :System.Attribute
private int & _ID;
private byte &_
public TCursorStruct(int ID,byte framecount )
_framecount =
public int ID
get{ return _ID;}
public byte framecount
get{ return _}
//鼠标类型//
public enum TCursorState
[TCursorStruct(0,0)] & & & & & &None,//系统光标样式//
[TCursorStruct(1,1)]
cCatch,//抓捕样式//
可以系统光标与抓捕样式可以相互切换
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:377520次
积分:5255
积分:5255
排名:第5213名
原创:109篇
转载:265篇
评论:30条
(1)(5)(9)(10)(13)(23)(11)(21)(24)(18)(32)(12)(23)(30)(44)(35)(62)(4)[System.Runtime.InteropServices.DllImport("user32.dll")] //引入dll
public static extern int SetCursorPos ( int x , int y );
void Update()
  SetMouseToAnyOfScreenPosition();
void SetMouseToAnyOfScreenPosition()
  SetCursorPos ( 20 , 20 );//放在update中,每帧调用,强制设置坐标
  Cursor . visible =//隐藏鼠标
阅读(...) 评论()u3d隐藏光标的问题【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:74,937贴子:
u3d隐藏光标的问题收藏
在u3d中除了Screen.showCursor =和 Screen.lockCursor =方法外,3.5版本中还有什么方法可以隐藏光标呢?EditorGUIUtility.AddCursorRect (Rect(10,10,100,100), MouseCursor.Link); 这句是什么意思呢?不报错,也没作用,EditorGUIUtility与MouseCursor的代码注释在哪里有呢?谢谢大神解答。
达内unity3d培训全程&实战教学&,unity3d金牌讲师授课.免费unity3d课程试听中!到达内unity3d学院学习unity3d,只需4个月速成unity3d游戏工程师.
EditorGUIUtility.AddCursorRect (Rect(10,10,100,100), MouseCursor.Link); 这一句和Screen.showCursor = false;这个是完全不一样的,首先Screen.showCursor只是隐藏和显示鼠标;而AddCursorRect 却是用在编辑器里的,只要是用来修改你编辑时的鼠标的样式,和运行时没有任何关系,MouseCursor.Link这个是鼠标样式,你现在的是链接样式。
登录百度帐号推荐应用}

我要回帖

更多关于 unity 光标位置 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信