我怎样才能永远重置和循环这个计时器?

时间:2021-07-06 06:02:52

标签: c# unity3d

当我们点击它时,我有一个按钮和一个计时器,我想知道如何制作它以便我可以将计时器设置回 0,如果我们点击退出按钮,计时器将再次循环,直到它在 80 和永远回到0?

我尝试了几种在最后添加 ttimer2 = 0 的方法,但它只会循环我的计时器而无需我单击按钮,感谢您提供任何帮助!

        if (CrossPlatformInputManager.GetButton("exit"))
        {
            if (ttimer2 < 80 && flag2)
            {
                ttimer2 += 1;
                UpDown = 2;
                Debug.Log(ttimer);
                transform.Translate(Vector3.up * speed * Time.deltaTime);
                darkin.SetBool("play", false);
                darkengame.SetActive(true);
            }
            else
            {
                flag2 = true;
                Debug.Log(ttimer);
                darkengame.SetActive(false);
            }



        }

1 个答案:

答案 0 :(得分:1)

您需要重置循环索引

int index = 0;
int maxIndex = 80;
if (CrossPlatformInputManager.GetButton("exit"))
    {
        if (index >= maxIndex && flag2)
        {
            index = 0;
        }
        else
        {
            index++;
        }



    }