How come this won't work? FindGameObjectsWithTag("t1" && "t2");

Hoy Hoy Hoy , I’m trying to find two tags at once.

it finds only the first tag.
I tried these

objects = GameObject.FindGameObjectsWithTag("obj1" && "obj2");


objects = GameObject.FindGameObjectsWithTag("obj1" || "obj2");

Cheers for any help :).


Because like the error (you should be getting) says, “error CS0019: Operator ‘&&’ cannot be applied to operands of type string' and string’”. It has not been defined what the result is when you logically “and” two strings.

That code should not compile at all.

I know it looks sensible to try to find objects with “tag1” ‘and’ “tag2”, but “&&” means “logical conjunction” in boolean algebra kind of “and”. It cannot be used in C# to group things together the way you’re trying to do.

Logical Conjusnction

If you want to find objects with multiple tags, I think you just have to make multiple calls to FindGameObjectsWithTag()