Check out example codes for "gameObject active". It will help you in understanding the concepts better.

Code Example 1

if (gameObject.activeSelf)
{
	// this happens when object is active
}

Code Example 2

using UnityEngine;public class Example : MonoBehaviour
{
    private GameObject[] cubes = new GameObject[10];
    public float timer, interval = 2f;    void Start()
    {
        Vector3 pos = new Vector3(-5, 0, 0);        for (int i = 0; i < 10; i++)
        {
            cubes[i] = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cubes[i].transform.position = pos;
            cubes[i].name = "Cube_" + i;
            pos.x++;
        }
    }    void Update()
    {
        timer += Time.deltaTime;
        if (timer >= interval)
        {
            for (int i = 0; i < 10; i++)
            {
                int randomValue = Random.Range(0, 2);
                if (randomValue == 0)
                {
                    cubes[i].SetActive(false);
                }
                else  cubes[i].SetActive(true);
            }
            timer = 0;
        }
    }
}

Learn ReactJs, React Native from akashmittal.com