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

碰撞游戏对象

建议更改

成功!

感谢你帮助我们提升 Unity 文档品质。虽然我们无法接受所有提交内容,但我们会阅读用户建议的每项更改内容,并在适用情况下进行更新。

关闭

提交失败

由于各种原因,你的建议更改内容无法提交。请在几分钟后<a>重试</a>。感谢你抽出时间帮助我们提升 Unity 文档品质。

关闭

取消

public 游戏对象 游戏对象;

描述

你要与其发生碰撞的游戏对象的碰撞器。(只读)

碰撞你游戏对象的游戏对象。访问此项以检查碰撞游戏对象的属性,例如,游戏对象的名称和标记。

using UnityEngine;

public class CollisionGameObjectExample : MonoBehaviour { //Detect collisions between the GameObjects with Colliders attached void OnCollisionEnter(Collision collision) { //Check for a match with the specified name on any GameObject that collides with your GameObject if (collision.gameObject.name == "MyGameObjectName") { //If the GameObject's name matches the one you suggest, output this message in the console Debug.Log("Do something here"); }

//Check for a match with the specific tag on any GameObject that collides with your GameObject if (collision.gameObject.tag == "MyGameObjectTag") { //If the GameObject has the same tag as specified, output this message in the console Debug.Log("Do something else here"); } } }