SetActive random object on list every x secondes?

Hi,
i have 5 objects in my scene
Every 10 seconds i want one object go randomly to setactive(true) and 4 other object are setactive(false).
everyonne have script for make that please ?
Thank you

Please note that it’s always appreciated if you post what you’ve got so far, even if it doesn’t work at all. At least show that you’ve tried on your own.

ho ok ^^

i have that .js code
but i want remplace Instantiate by Setactive(true)

public var prefabs : GameObject[ ] = new GameObject[8];
var timeDelay = 5;

function Start()
{
while (true)
{
yield WaitForSeconds(timeDelay);
Instantiate(prefabs[Random.Range(0,prefabs.length)], transform.position, Quaternion.identity);
}
}

I would strongly recommend you go through the beginner programming tutorials here:

As what you are asking is very simple, especially with the code you already have, you should know how to make a loop to iterate through your objects and how to disable them, and then enable only the random index afterwards.

I’d just store the active one in a seperate variable, that eliminates the loop as well. :smile:

Ok Thank you for all :smile: