Basically what I am trying to do is to gave a sprite that is on my screen to blink on for a few seconds and then blink off, and I want this to happen as a constant loop. I know instead of deactivating the game object itself I should just activate and deactivate the renderer and use wait for seconds for the pauses, but I am unsure how this script is would be formatted.
If anybody can help me that would be great. Thank you in advance.
edit I also just wanted to make note that the sprite I am using is through Unity 5`s UI system.
void Start()
{
StartCoroutine(StartBlinking()); //Doesn't need to be in Start() but use this line wherever you need it.
}
IEnumerator StartBlinking()
{
yield return new WaitForSeconds(1); //However many seconds you want
theSprite.GetComponent<SpriteRenderer>().enabled = !theSprite.GetComponent<SpriteRenderer>().enabled; //This toggles it
StartCoroutine(StartBlinking());
}
In the editor drag the sprite into the “The Sprite” box. Or you could attach this script to the sprite itself and replace “theSprite” in the code with “this”.
Since this is stopping all coroutines in the whole script, you should probably keep this in a script by itself or make sure you have no other coroutines in the script.