您的位置:首页 > 移动开发 > Unity3D

关于unity3的中的碰撞检测

2012-07-31 16:26 441 查看
最近在研究unity3d,关于碰撞检测百度一下出来好多,都是说如下几个函数

OnTriggerEnterOnTriggerEnter is called when the Collider other enters
the trigger.

OnTriggerExitOnTriggerExit is called when the Collider other has
stopped touching the trigger.
OnTriggerStayOnTriggerStay is called almost all the frames for every Collider other that
is touching the trigger.
OnCollisionEnterOnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
OnCollisionExitOnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
OnCollisionStayOnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
哎,也许是本人不才怎么搞都不走这几个函数,可能是网上的步骤太简单了。
下边我说下我的详细步骤吧,

首先假设场景中有一个椅子chair和一个默认的camera,然后建立一个脚本movecamera.js,将这个脚本附加到camera上,并且加上OnCollisionEnter函数。

然后给camera加上组件character controller,(具体怎么加,选中camera然后component-》physics-》character controller)。

再选中chair给它加上组件mesh collider(网格碰撞器)和rigidbody(具体怎么加同上)。然后播放后,移动camera到椅子那里就回走OnCollisionEnter这个函数了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: