Unity3d 碰撞检测
时间: 2024-04-26 20:26:13 浏览: 119
Unity3d中有两种检测碰撞发生的方式,一种是利用碰撞器,另一种是利用触发器。碰撞器是一组组件,包括Box Collider、Capsule Collider等,它们必须添加到GameObject上。而触发器只需要在碰撞器组件的检视面板中勾选IsTrigger属性选择框。在Unity3d中,我们可以使用以下接口函数来处理这两种碰撞检测:
- 触发信息检测:
- MonoBehaviour.OnTriggerEnter(Collider other):当进入触发器时调用。
- MonoBehaviour.OnTriggerExit(Collider other):当退出触发器时调用。
- MonoBehaviour.OnTriggerStay(Collider other):当逗留在触发器中时调用。
- 碰撞信息检测:
- MonoBehaviour.OnCollisionEnter(Collision collisionInfo):当进入碰撞器时调用。
- MonoBehaviour.OnCollisionExit(Collision collisionInfo):当退出碰撞器时调用。
- MonoBehaviour.OnCollisionStay(Collision collisionInfo):当逗留在碰撞器中时调用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Unity3D入门(二):碰撞检测](https://blog.csdn.net/zooen2011/article/details/12245529)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Unity3D —— 碰撞检测](https://blog.csdn.net/wxy15979115440/article/details/103609899)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Unity 3D之碰撞检测](https://blog.csdn.net/m0_74427422/article/details/129170479)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文