Question by
Kobaxidze · May 22, 2016 at 02:49 PM ·
gameobject.tag
How to check if two objects have same tag?
Hello, I made two objects, with same tag. And I need to check if these two objects have a same tag. How can I get current object's tag? I managed to get second object's tag but not firsts.. Please help..
void OnTriggerEnter2D (Collider2D other) {
if (other.tag == "Red")
player.transform.position = spawnPoint.transform.position;
}
Comment
Answer by SimplyMabu · Jul 19, 2018 at 01:34 PM
so I just had this same question, kinda tested stuff out, and was really surprised it worked this way (not because it's all that surprising, just because it was easy!) I'm hoping I'm understanding your question and that it's the same as mine was but this is how I worked it out!
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag(this.gameObject.tag))
Debug.Log("does it work this way??");
}
spoiler alert: it did!
Your answer
![](https://koobas.hobune.stream/wayback/20220612081316im_/https://answers.unity.com/themes/thub/images/avi.jpg)