is there a way to start another coroutine once the last coroutine is finish. I have a button that activates a coroutine, the button can be pressed any time you want, when pressed you activate a coroutine. However I notice that when you press the button twice the coroutine happens twice, which is not want I want. Is there a way to make sure that once my Boomerangeffect(coroutine) is activate the coroutine can't start (if button is pressed) until the present coroutine is finished.
public GameObject BoomerangOn, BoomerangOff;
public static int buttonCount = 4;
static int timesActivated = 0;
void Start()
{
if (PlayerPrefs.HasKey ("boomerangbutton")) {
buttonCount = PlayerPrefs.GetInt ("boomerangbutton");
}
}
void Update()
{
PlayerPrefs.SetInt("boomerangbutton", buttonCount);
}
public void Activated ()
{
if(timesActivated < buttonCount)
{
timesActivated++;
StartCoroutine(BoomerangEffect());
}
}
IEnumerator BoomerangEffect()
{
BoomerangOn.SetActive (true);
yield return null;
yield return new WaitForSeconds (10.0f);
yield return null;
BoomerangOn.SetActive (false);
yield return null;
BoomerangOff.SetActive (true);
yield return null;
yield return new WaitForSeconds (1f);
yield return null;
BoomerangOff.SetActive (false);
yield return null;
}
yield return null;
? Are you sure you need them? \$\endgroup\$