C# find game object with tag and set active?

in c# how do you find a tame object with “TAG” and .SetActive(true?)

You can only find GameObjects that are currently active.

GameObject.FindWithTag() will return the first GameObject found that is active with the given tag.

Then there is GameObject.FindGameObjectsWithTag(). This returns an array of active GameObjects with the given tag if there are any to be found. If none exist an empty array will be returned.

I always use the following for GameObject.FindWithTag()

GameObject go = null;
if (GameObject.FindWithTag("MyTag") != null)
{
    go = GameObject.FindWithTag("MyTag");
}
if (go != null)
{
    // use it
}

or for GameObject.FindGameObjectsWithTag()

GameObject[] goArray = GameObject.FindGameObjectsWithTag("MyTag");
if (goArray.Length > 0)
{
    // this is an array, use it so
    GameObject go = goArray[0];

    // or
    for int (i = 0; i < goArray.Length; i++)
    {
        GameObject go = goArray*;*

}
}
or if you prefer to use a list
using System.Collections.Generic;
List goList = new List();
goList = new List(GameObject.FindGameObjectsWithTag(“MyTag”));
if (goList.Count > 0)
{
// this is a list, use it so
GameObject go = goList[0];
// or
for int (i = 0; i < goList.Count; i++)
{
GameObject go = goList*;*
}
}

Use GameObject.FindWithTag (“TAG”);

https://docs.unity3d.com/ScriptReference/GameObject.FindWithTag.htm

And then set that gameobject as active or inactive just like you mentioned-

thisgameObject.SetActive (true);