Restricting onMouseDown event on specific collides

陌路散爱 提交于 2019-12-11 07:55:10

问题


As you know, OnMouseDown work on mouse click but its run on every collider. My simple question is can i restrict OnMouseDown event to run on some specfic colliders not all collider as I am using some collider for trigger. Those some collider which i am using for trigger don't want to hit through onMouseDown.


回答1:


You can try raycasting from the mouseposition and get the collider hit. This is what I would advice. This would do the trick: https://docs.unity3d.com/ScriptReference/Input-mousePosition.html Just do the raycasting and test for the collider hit.

If you need more adivce, let me know.

My personal adivce would be to replace the mouseDownEvent with the Input.getMouseButtonDown(0) and place it inside Update.



来源:https://stackoverflow.com/questions/42465363/restricting-onmousedown-event-on-specific-collides

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!