Unityで時間をはかる

    float time = 5;
    float timeleft;
    private void Update()
    {
        timeleft -= Time.deltaTime;
        if(timeleft <= 0)
        {
            Debug.Log("時間経過");
            timeleft = time;
        }
    }

もしくは

 float nextTime;
    float interval = 5;
    private void Update()
    {
        if(Time.time >= nextTime)
        {
            Debug.Log("時間経過");
            nextTime = Time.time + interval;
        }
    }

Updateの中で呼ばれてないといけません。

コメント

タイトルとURLをコピーしました