unity中的MonoBehaviour.OnMouseDown()

在官网的api文档中仅说明了

Description

OnMouseDown is called when the user has pressed the mouse button while over theGUIElement orCollider.

This event is sent to all scripts of the Collider or GUIElement.


首先OnMouseDown()对2d和3d的物体都有效。


经过我的试验。B是A子物体,假设A和B都有collider,点击谁就运行谁脚本的OnMouseDown()。

并且仅仅能点到最外的物体。比方A和B是两个独立的物体。A把B遮到了,就仅仅能点到A。B是不会运行的。

(说个话外题:禁用脚本仅仅是禁用了awake(),start(),update(),fixedupdate(),ongui()五个函数,其它的还是有效的)。


原文地址:https://www.cnblogs.com/bhlsheji/p/5133245.html