- Home /
Random time activate/deactivate object
Hi, firs of all sory about my english. The thing is that i wanna make an object to be active/unactive in a variable (between 2 times). If i use a single interval it works perfect, but if i set up it with random range it only appear at the maximum amount of time.
var interval : float = 1.0f; //////not using this for the moment var min : float = 1.0f;//////not using this for the moment var max : float = 2.0f;//////not using this for the moment
function Start()
{
InvokeRepeating ("Toogle", (Random.Range(1.0f, 1.0f)), (Random.Range(5.0f, 10.0f)));
}
function Toggle()
{
gameObject.active = !gameObject.active;
}
Answer by hav_ngs_ru · Jan 23, 2015 at 01:50 PM
In Start you call Random once, if it return 7, for example - if shedules Toggle to be called every 7 seconds, and you neve try to change it later. try this:
function Start()
{
Invoke ("Toogle", (Random.Range(min, max));
}
function Toggle()
{
gameObject.active = !gameObject.active;
Invoke ("Toogle", (Random.Range(min, max));
}
here we redefine "next call interval" after every Toggle call.
Your answer
Follow this Question
Related Questions
Random time interval 1 Answer
How to my objects randomly active? 1 Answer
Check if var is true from a random object 0 Answers
Selecting Random Object and Setting Variable to True 2 Answers
Randomize Spawn Time 2 Answers