How to set gameobject inactive if random.range decides to choose the same gameobject

Hello I’m trying to make a simple trivia game a little more difficult for me to make then I expected lol but I have gameobjects that are set active randomly then back to inactive but I would like for it to go inactive then back to active if unity decides to choose the same gameobject currently it just remains active then go inactive I have a game manager script on a empty gameobject controlling all of the gameobjects.


public GameObject[] anw;
int index;
private float timeBtwAct;
public float startTimeBtwAct, actWait;

void Update()
    if (timeBtwAct <= 0)
        index = Random.Range(0, anw.Length);

        for (var i = 0; i < anw.Length; i++)
            AnswersScript answers = anw*.GetComponent<AnswersScript>();*

if (!
timeBtwAct = actWait;
timeBtwAct -= Time.deltaTime;

Not sure I understand but if you want your gameobject to be inactive for just a period of time, you should use a Coroutine to make it go active/inactive after X seconds or any event that you want.

I think that this may be what you are looking for


This line will toggle their state, so would take care of both activating and deactivating.