版本:Unity 6(6000.0)
语言英语
  • C#

Collision.collider

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。尽管我们无法接受所有提交的内容,但我们确实会阅读用户建议的每项更改,并在适用场合进行更新。

关闭

提交失败

由于某种原因,无法提交您建议的更改。请在几分钟后再次尝试。感谢您花时间帮助我们提高 Unity 文档的质量。

关闭

取消

public 碰撞器 碰撞器;

说明

我们命中的碰撞器(只读)。

获取你的游戏对象命中的游戏对象的碰撞器。要详细查找命中所有碰撞器,必须迭代接触点(接触属性)。

//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!"); } } }