代码之家  ›  专栏  ›  技术社区  ›  Alex Bratov

单位C#如何检查(语句)在n个时间段内是否为真?

  •  0
  • Alex Bratov  · 技术社区  · 2 年前

    我有一个 If n 时间量(帧、秒)?我需要bool仅在条件为true的半秒钟内返回false。

    1 回复  |  直到 2 年前
        1
  •  1
  •   jjxtra    2 年前

    public class MyScript : MonoBehaviour
    {
        float timer:
    
        void Update()
        {
            // If condition is false, reset timer and return out. Replace condition with your logic.
            if (!condition)
            {
                timer = 0.0f;
                return;
            }
          
            timer += Time.deltaTime:
            if (timer > 0.5f)
            {
                // do stuff
    
                timer = timer - 0.5f; // reset timer
            }
        }
    }