Skip to main content
added 491 characters in body; edited tags
Source Link
Theraot
  • 28.3k
  • 4
  • 55
  • 83

enter image description here

private IEnumerator FlickerEffectInTime()
{
    while(true)
    {
        startTime += Time.deltaTime;
        if (startTime < 2)
        {
            GetComponent<SpriteRenderer>().enabled = !GetComponent<SpriteRenderer>().enabled;
            Debug.Log(startTime);
            yield return new WaitForSeconds(0.1f);
        }
        else
        {
            startTime = 0;
            GetComponent<SpriteRenderer>().enabled = true;
            Debug.Log("stoped flick");
            StopCoroutine("FlickerEffectInTime");

        }
    }
}

The while loop is infinite I have use StopCourotine()StopCourotine() How can I resolve it ?

enter image description here

The while loop is infinite I have use StopCourotine() How can I resolve it ?

private IEnumerator FlickerEffectInTime()
{
    while(true)
    {
        startTime += Time.deltaTime;
        if (startTime < 2)
        {
            GetComponent<SpriteRenderer>().enabled = !GetComponent<SpriteRenderer>().enabled;
            Debug.Log(startTime);
            yield return new WaitForSeconds(0.1f);
        }
        else
        {
            startTime = 0;
            GetComponent<SpriteRenderer>().enabled = true;
            Debug.Log("stoped flick");
            StopCoroutine("FlickerEffectInTime");

        }
    }
}

The while loop is infinite I have use StopCourotine() How can I resolve it ?

Source Link

Why can't I stop Coroutine?

enter image description here

The while loop is infinite I have use StopCourotine() How can I resolve it ?