백지부터 시작하는 이세계 코딩 생활

CompareTag 비교 본문

백지부터 시작하는 이세계 유니티 생활 since 2020

CompareTag 비교

조아덕 2021. 1. 11. 17:16
other.gameObject.CompareTag("Player"

각각의 Object들에 할당되어있는 Tag값을 확인할 때 사용한다.

ex) 확인한 태그의 값에 따라 특정 이벤트를 구현한다.


 

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

Ref.

1 jayprogram.tistory.com/35

 

[Unity] tag 비교하기('CompareTag()' VS '== tag')

유니티 프로그램을 개발하면서 Tag를 사용할 때가 많습니다. 제가 현재 개발하고 있는 게임에서는 플레이어와 몹이 충돌했는지 여부를 판단하기 위해 태그를 사용하고 있습니다. 아래 소스와 같

jayprogram.tistory.com

2 docs.unity3d.com/ScriptReference/Component.CompareTag.html

 

Unity - Scripting API: Component.CompareTag

Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close

docs.unity3d.com

 

'백지부터 시작하는 이세계 유니티 생활 since 2020' 카테고리의 다른 글

ScreenToWorldPoint  (1) 2021.01.12
Invoke, InvokeRepeating  (0) 2021.01.11
Preserve Aspect  (0) 2021.01.05
Delegate 와 Event (키워드)  (0) 2020.12.31
Animation State (Any State)  (2) 2020.12.29
Comments