Check if a object with a specific tag exists in an array


I have run into a problem that has stumped me a bit. I have some code that returns an array of colliders, and I need to be able to check if an object with a specific tag exists in that array, and if it does, set some kind of value and then change the value back when there no longer is an object with that specific tag in the array anymore. But the problem is that I can’t figure out a way to do this.

So to make the actual question more clear.

  1. How can I check if one or multiple objects with a specific tag exists in a array?
  2. How can I detect if no object(s) with a specific tag exists?

If it is to any help or anything, this is the code I use to get the objects.

private Collider[] m_colliders;
public LayerMask m_layers;

// Update is called once per frame
void Update()
    m_colliders = Physics.OverlapSphere(transform.position, 0.5f, m_layers, QueryTriggerInteraction.Ignore);

EDIT: It just turns out I’m a bit of an idiot. The way I thought was wrong was actually right, i.e, looping through the objects. So I just added this piece of code that did the trick for my situation.

bool ContainsTag(string tag)
    for (int i = 0; i < m_colliders.Length; i++)
        if (m_colliders*.tag == tag)*

return true;

return false;

You’d loop through the array, and check each object to see if it has a matching tag, and store that in an appropriately scoped boolean variable.