Component.CompareTag

Unity · Версия 2020.3 LTS · Scripting · Component

Component.CompareTag

Объявление

public bool CompareTag(string tag);

Параметры

tag Тег для сравнения.

Описание

Помечен ли этот игровой объект тегом tag?

// Immediate death trigger.
// Destroys any colliders that enter the trigger, if they are tagged player.
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            Destroy(other.gameObject);
        }
    }
}

Обновлено 17 ноября 2026 г.