情景
RPG游戏中玩家打开背包,鼠标移动到道具(类型为UI->Image)上,显示物品摘要;右键道具,则使用掉该物品。
遇到的问题
UI控件挂载包含OnMouseOver函数的脚本后,鼠标移动到该控件上但OnMouseOver未触发。
原因分析
首先我们看官方文档中对于OnMouseOver使用条件的介绍:
Called every frame while the mouse is over the GUIElement or Collider.
A call to OnMouseEnter occurs on the first frame the mouse is over the object. OnMouseOver is then called each frame until the mouse moves away, at which point OnMouseExit is called.
This function is not called on objects that belong to Ignor