Hi, I´m new to unity(started learning it last week) and I´m currently trying to develop a speech bubble to stay always on top of the player. The bubble will be invisible at first sight but, from time to time, it will appear with a random joke.
I already know how to play with the alpha of it(it´s a sprite renderer), so I made this:
public float segBalaoAparecer;
public float segBalaoDesaparecer;
public SpriteRenderer spriteDesaparecer;
// Use this for initialization
void Start () {
spriteDesaparecer.color = new Color (1f, 1f, 1f, 0f);//sprite invisivel no comeco
StartCoroutine("showBaloon");
}
IEnumerator showBaloon()
{
while (true)
{
yield return new WaitForSeconds(segBalaoAparecer);
Debug.Log("showBaloon chamada");
spriteDesaparecer.color = new Color (1f, 1f, 1f, 1f);
Debug.Log("balao ficou visivel");
yield return new WaitForSeconds(segBalaoDesaparecer);
spriteDesaparecer.color = new Color (1f, 1f, 1f, 0f);
Debug.Log("balao ficou invisivel");
}
}
the problem is: showBaloon has a while(true) inside it and I´m afraid of freezing the game because of it. Can anyone help me overcome it? Oh, and the method must have these waitForSeconds, I can´t remove them.