打破Unity中的while循环?

时间:2019-05-22 07:59:17

标签: c# unity3d

如何摆脱协程内部的while循环? 即使达到该值,调试消息也会连续出现。

void Start()
    {
        StartCoroutine(StartFadingIn());

    }
IEnumerator StartFadingIn()
    {
        float i = 0f;
        while(i!=1f)
        {
            Color color = Downward.material.color;
            color.a = i;
            Downward.material.color = color;
            yield return new WaitForSeconds(0.05f);
            i = i+0.1f;
            Debug.Log("Repeat");
        }
    }

1 个答案:

答案 0 :(得分:0)

void Start()
{
    StartCoroutine(StartFadingIn());

}
IEnumerator StartFadingIn()
{
    float i = 0f;
    while (Mathf.Abs(i - 1f) > 1e-5)
    {
        Color color = Downward.material.color;
        color.a = i;
        Downward.material.color = color;
        yield return new WaitForSeconds(0.05f);
        i = i+0.1f;
        Debug.Log("Repeat");
    }
}
相关问题