How to change layer of Gameobjects with same tags?

I am currently making a pause menu and I have some gameobjects with colliders being instantiated. When the game is paused, I want the colliders to not respond to click.

I have tried changing the layer to “Ignore Raycast” which works but it only works for one gameobject at a time since I have no idea how to implement a SetLayerRecursively function.

What would be best for me to disable the colliders during runtime with script?`

public GameObject pausePanel, resumeButton, pauseButton, aobdt;

public void Start(){
	OnUnpause ();
}

public void OnPause(){
	pausePanel.SetActive (true);
	pauseButton.SetActive (false);
	aobdt.SetActive (false);
	Time.timeScale = 0;
	Debug.Log ("Game has been paused");

	//This part only disables the first number that comes on
	//I need to make it in a way so that it changes the layer for each and every one of them
	GameObject.FindWithTag ("Numbers").layer = LayerMask.NameToLayer("Ignore Raycast");
	Debug.Log (GameObject.FindWithTag ("Numbers").layer);

}

public void OnUnpause(){
	pausePanel.SetActive (false);
	pauseButton.SetActive (true);
	aobdt.SetActive (true);
	Time.timeScale = 1;
	Debug.Log ("Game has resumed");

	GameObject.FindWithTag ("Numbers").layer = LayerMask.NameToLayer("Default");
	Debug.Log (GameObject.FindWithTag ("Numbers").layer);
}

`

A ‘foreach’ loop is what you are looking for. The code below works to change everything with the tag ‘Numbers’ onto a the same layer. Tested and working! Just add into your code.

If instead of changing layers you wish to disable the colliders - not something I would do off-the-bat since their may be other consequences with physics etc. - you can call the collider component in the same way we call the layer.

using UnityEngine;
using System.Collections;

public class FindAllTagged : MonoBehaviour {

	public GameObject[] taggedObjects;

	//calls all the objects with a tag and stores them as a simple array


	void Start () {
		taggedObjects = GameObject.FindGameObjectsWithTag("Numbers");

	}

	void OnPause()
	{
		//all your other stuff and then instead of the single iteraction of changing the mask, try a foreach loop
		foreach (GameObject number in taggedObjects)
		{
			number.layer = LayerMask.NameToLayer("Ignore Raycast");
		}
	}

	void OnUnpause()
	{
		//again, just resetting back too their 'default' layer
		foreach (GameObject number in taggedObjects)
		{
			number.layer = LayerMask.NameToLayer("Default");
		}
	}