Version: 2017.3
public string tag ;

Description

Тег данного игрового объекта.

A tag can be used to identify a game object. Tags must be declared in the Tags and Layers manager before using them.

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"); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961