This question was
closed May 09, 2018 at 10:33 PM by
tormentoarmagedoom for the following reason:
The question is answered, right answer was accepted
How to check if gameobject has a tag, from a list.
How would I check if a gameobject that collided with my trigger has one of these tags from this list, anyone of them. This is as far as I got, dont know if theres a way do this.
public string[] TagList = { "Ball", "Box" };
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == TagList[0-1])
{
//Do Something
}
}
Comment
Best Answer
Answer by tormentoarmagedoom · May 09, 2018 at 10:29 PM
Good day.
You should use a "foreach" sentence. Like this
public string[] TagList = { "Ball", "Box" };
public void OnTriggerEnter(Collider other)
{
foreach (string TagToTest in TagList)
{
if (other.gameObject.tag == TagToTest )
{
//Do Something
}
{
}
So now, when collide, it will check every element in TagList to see if is the same as the object. So you cna make the list al long as you want!
If helped, accept the answer!
Bye :D
Follow this Question
Related Questions
Can i tag collider? 1 Answer
Need Help With Collider Script. 2 Answers
"error CS1501: No overload for method `Add' takes `2' arguments" 0 Answers