Unity3D 中鼠标按下时OnMouseDown()、Input.GetMouseButtonDown()和EventType.MouseDown的响应验证
2014-10-09 21:59
429 查看
初学unity3D,对于其中的事件响应不是很清楚,于是写了下面的代码来验证:
1、新建.cs文件,名为testMouse.cs:
2、场景中的游戏对象很简单,只有一个Cube和主相机。
3、将testMouse.cs组件附加到Cube上面,运行游戏,当用鼠标点击Cube时,会有如下显示:
4、当用鼠标单击任何除Cube外的位置都会产生如下响应:
5、这说明Event和Input.GetMousexxx事件会被任何gameobject监控到,而OnMousexxx事件只会被该脚本附加上的gameobject监控到。
6、为什么Event事件要写在OnGUI函数里面呢?可以再这两个文档中找到线索:
a、http://game.ceeger.com/Script/MonoBehaviour/MonoBehaviour.OnGUI.html
b、http://game.ceeger.com/Script/Event/Event.html
OnGUI函数在每帧会被调用多次。
1、新建.cs文件,名为testMouse.cs:
using UnityEngine; using System.Collections; public class testMouse : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { Debug.Log("Input.GetMouseButtonDown response"); } } void OnMouseDown() { Debug.Log("OnMouseDown response"); } void OnGUI() { if (Event.current != null && Event.current.type == EventType.mouseDown) { Debug.Log("EventType.mouseDown response"); } } }
2、场景中的游戏对象很简单,只有一个Cube和主相机。
3、将testMouse.cs组件附加到Cube上面,运行游戏,当用鼠标点击Cube时,会有如下显示:
4、当用鼠标单击任何除Cube外的位置都会产生如下响应:
5、这说明Event和Input.GetMousexxx事件会被任何gameobject监控到,而OnMousexxx事件只会被该脚本附加上的gameobject监控到。
6、为什么Event事件要写在OnGUI函数里面呢?可以再这两个文档中找到线索:
a、http://game.ceeger.com/Script/MonoBehaviour/MonoBehaviour.OnGUI.html
b、http://game.ceeger.com/Script/Event/Event.html
OnGUI函数在每帧会被调用多次。
相关文章推荐
- Unity3D 中鼠标按下时OnMouseDown()、Input.GetMouseButtonDown()和EventType.MouseDown的响应验证
- Unity3d 鼠标的事件GetMouseButtonDown()、GetMouseButton()、GetMouseButtonUp()
- Unity3d 鼠标的事件GetMouseButtonDown()、GetMouseButton()、GetMouseButtonUp()
- Unity3D系列2:Input.GetButtonDown没有正确响应
- Unity3d 鼠标的事件GetMouseButtonDown()、GetMouseButton()、GetMouseButtonUp()
- wpf button的mouse(leftbutton)down/up,click事件不响应解决办法
- 3D Slicer Modify Mouse Event 修改3D Slicer中的鼠标响应事件
- Unity中的Input.GetMouseButton,GetMouseButtonDown,GetMouseButtonUp
- Unity 鼠标事件 GUI GUILayerOut Input Application(截屏,getMouseDown,getKeyCode) 射线
- 如何解决Button不响应MouseLeftButtonDown与MouseLeftButtonUp事件的问题
- (转)silverlight中button不响应mouseleftbuttondown的原因
- 解决MouseLeftButtonDown在Grid等布局中无法响应事件 - [Silverlight开发]
- Input.GetButtonDown没有正确响应
- Input.GetMouseButton 获取鼠标按钮
- Input.GetMouseButtonDown()方法 &Input.GetMouseButton()方法
- TrackMouseEvent函数实现鼠标停留响应
- wpf button的mouse(leftbutton)down/up,click事件不响应解决办法
- wpf button的mouse(leftbutton)down/up,click事件不响应解决办法
- Input.GetMouseButtonDown 在fixedupdate中会出现丢失问题,在update中则完全没这个问题
- TrackMouseEvent函数实现鼠标停留响应