본문 바로가기

Game Programming/Unity

[유니티] 태그 비교: '==' vs 'CompareTag'

// Get hit at basket
if (other.gameObject.tag == "Basket")
{
    itemManager.instance.GetScore(1);
}

 

tag 비교를 이렇게 했더니

명시적 문자열 비교는 비효율적입니다. 대신 'CompareTag'를 사용하세요

오늘도 조언해주시는 라이더씨

 

 

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

API 문서

other.gameObjet.compareTag() -> 이렇게 쓰려고 했는데

gameObject 생략해도 된다고 하네요~

// Get hit at basket
if (other.CompareTag("Basket"))
{
    itemManager.instance.GetScore(1);
}

최종 수정!