问题描述
我的项目遇到问题.我想知道鼠标点赞发生在GUI或任何游戏对象上.我已经试过了,但是显示空引用异常
I got a problem in my project. I want to know that mouse cliked happend on GUI or on any game object.I have tried this but it is showing null reference exception
EventSystem eventSystem = EventSystem.current;
if (eventSystem.IsPointerOverGameObject())
Debug.Log("left click over a gui element");
如何检测?有没有可用的活动?
how to detect?? Is there any event available or else?
推荐答案
最后得到了我的答案此处:视频教程中演示了三种方法.这部影片救了我:).
Finally got my answer here:There are three ways to do this, as demonstrated in this video tutorial. this video save me:).
-
使用EventSystem.current.IsPointerOverGameObject
Use EventSystem.current.IsPointerOverGameObject
将您的OnMouseXXX和Raycasts转换为EventSystem触发器.在相机上使用物理光线投射器
Convert your OnMouseXXX and Raycasts to an EventSystem trigger. Use a physics raycaster on the camera
从EventSystems命名空间实现各种处理程序接口.在相机上使用物理光线投射器.
Implement the various handler interfaces from the EventSystems namespace. Use a physics raycaster on the camera.
这篇关于检测鼠标在GUI上的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!