我是靠谱客的博主 失眠路人,这篇文章主要介绍【unity学习笔记】OnMouseEnter、OnMouseOver、OnMouseExit,现在分享给大家,希望可以做个参考。

声明:此篇文章是个人学习笔记,并非教程,所以内容可能不够严谨。可作参考,但不保证绝对正确。如果你发现我的文章有什么错误,非常欢迎指正,谢谢哦

OnMouseEnter、OnMouseOver、OnMouseExit这三个函数类似于OnCollisionEnter、OnCollisionStay、OnCollisionExit函数,只不过后者是在两个碰撞体相互碰撞时自动调用,而前者是鼠标进入碰撞体范围内时自动调用。

函数功能
OnMouseEnter当鼠标进入当前脚本所在物体的碰撞体时,自动调用此函数
OnMouseOver当鼠标悬停在当前脚本所在物体的碰撞体上时,自动调用。如果碰撞体设为了isTrigger,那么只有Physics.queriesHitTriggers设为true时才会调用
OnMouseExit当鼠标离开当前脚本所在物体的碰撞体时,自动调用
  void OnMouseOver()
    {
        //If your mouse hovers over the GameObject with the script attached, output this message
        Debug.Log("Mouse is over GameObject.");
    }

    void OnMouseExit()
    {
        //The mouse is no longer hovering over the GameObject so output this message each frame
        Debug.Log("Mouse is no longer on GameObject.");
    }

最后

以上就是失眠路人最近收集整理的关于【unity学习笔记】OnMouseEnter、OnMouseOver、OnMouseExit的全部内容,更多相关【unity学习笔记】OnMouseEnter、OnMouseOver、OnMouseExit内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部