限制特定碰撞的 onMouseDown 事件 [英] Restricting onMouseDown event on specific collides

查看:36
本文介绍了限制特定碰撞的 onMouseDown 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所知,OnMouseDown 处理鼠标点击,但它在每个碰撞器上运行.我的简单问题是我可以限制 OnMouseDown 事件在某些特定对撞机上运行,​​而不是在所有对撞机上运行,​​因为我正在使用一些对撞机进行触发.我用于触发器的那些碰撞器不想通过 onMouseDown.

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.

推荐答案

您可以尝试从鼠标位置进行光线投射并获得对撞机命中.这就是我的建议.这可以解决问题:https://docs.unity3d.com/ScriptReference/Input-mousePosition.html 只需进行光线投射并测试碰撞体.

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.

我个人的建议是将 mouseDownEvent 替换为 Input.getMouseButtonDown(0) 并将其放置在 Update 中.

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

这篇关于限制特定碰撞的 onMouseDown 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆