Question by
automaticwriting · Aug 09, 2019 at 06:24 AM ·
waitforsecondsboolloops
Looped bool with timed delay
I'm wanting the bool to turn on and off with a 1 second delay, but cant get it to work. What am I missing?
void Start() { StartCoroutine(OnOff()); }
IEnumerator OnOff()
{
while (true)
{
on = true;
yield return new WaitForSeconds(1);
on = false;
}
}
Comment
Answer by Dragate · Aug 09, 2019 at 06:39 AM
No delay when switching from false to true. You need to add it.
IEnumerator OnOff() {
while (true) {
on = true;
yield return new WaitForSeconds(1);
on = false;
yield return new WaitForSeconds(1);
}
}