UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Collision.collider
# [Collision](https://docs.unity3d.com/cn/2019.4/ScriptReference/Collision.html).collider public [Collider](https://docs.unity3d.com/cn/2019.4/ScriptReference/Collider.html) **collider** ; ## 描述 我们撞击的 [Collider](https://docs.unity3d.com/cn/2019.4/ScriptReference/Collider.html)(只读)。 获取 GameObject 撞击的 GameObject 的 Collider。 要详细查找被撞击的所有碰撞体,必须迭代这些接触点([contacts](https://docs.unity3d.com/cn/2019.4/ScriptReference/Collision-contacts.html) 属性)。 ``` //In this example, the name of the GameObject that collides with your GameObject is output to the console. Then this checks the name of the Collider and if it matches with the one you specify, it outputs another message. //Create a GameObject and make sure it has a Collider component. Attach this script to it. //Create a second GameObject with a Collider and place it on top of the other GameObject to output that there was a collision. You can add movement to the GameObject to test more. using UnityEngine; public class Example : MonoBehaviour { //If your GameObject starts to collide with another GameObject with a Collider void OnCollisionEnter(Collision collision) { //Output the Collider's GameObject's name Debug.Log(collision.collider.name); } //If your GameObject keeps colliding with another GameObject with a Collider, do something void OnCollisionStay(Collision collision) { //Check to see if the Collider's name is "Chest" if (collision.collider.name == "Chest") { //Output the message Debug.Log("Chest is here!"); } } } ```
da
2022年5月25日 10:48
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码