- Home /
if collision.gameObject.tag == any of the elements in the array...
Hey there, first time posting here :) So my question is: How can i check if the collision object's tag is equal to any of the elements in my array? I'm working on a game where there are different bombs. Each bomb has a different color (blue, red, orange...), and each bomb will only be affected by the shockwaves of it's own color. For this, i have created an array of strings, however i don't know how i'm supposed to check if the collision.gameObject.tag is equal to any of it's elements. Thanks in advance!
If you do that, it will return true for ALL bombs, if the array contains every possible color. It seems like you want to check if the tag is equal to that of the shockwave (which does not require you to check through an entire array). As for your question in general: You need to check through each item of the array individually to see if there is any match. If you use generic lists however, there is a neat method called "exists" which tells you if the value/reference you provide exists in a certain list.
Your answer
![](https://koobas.hobune.stream/wayback/20220613152932im_/https://answers.unity.com/themes/thub/images/avi.jpg)