I Need to Enable and Disable Multiple Gameobjects that contain Same Tag in Unity. C#,I need to enable and disable multiple game objects that contain same tag
This is the way i’d do it, it’s not a “good performance” way but should work.
private GameObject[] objs;
void Start()
{
objs = FindObjectsOfType(GameObject); // this will look for all gameobjects and add them in the objs array
}
//Use this to disable all gameobjects with your tag
public void DisableGO()
{
foreach(GameObject obj in objs)
{
if(obj.CompareTag("YOUR TAG HERE"))
{
obj.SetActive(false);
}
}
}
//use this to enable all gameobjects with your tag
public void EnableGO()
{
foreach(GameObject obj in objs)
{
if(obj.CompareTag("YOUR TAG HERE"))
{
obj.SetActive(true);
}
}
}