Timer Class

I made a timer class to make all that kind of thing easy. I don’t know what to do for game pause yet.

using System;
using UnityEngine;

public class Timer
{
    float timerAmount;
    float timerTime;
    bool paused;

    public Timer(float length)
    {
        timerAmount = length;
    }

    public Timer()
    {

    }

    public float Amount
    {
        get { return timerAmount; }

        set
        {
            Reset(value);
        }
    }

    public bool Expired
    {
        get
        {
            return Time.time > timerTime;
        }
    }

    public bool Paused { get { return paused; } }

    public void SetPause(bool pause)
    {
        paused = pause;

        if (paused)
        {

        }
        else
        {

        }
    }

    public void Reset(float length)
    {
        timerAmount = length;
        timerTime = timerAmount + Time.time;
    }

    public void Reset()
    {
        timerTime = timerAmount + Time.time;
    }
}

Hi Zimmer,

I don’t know what to do for game pause yet.

Perhaps this can help;

You may want to consider using Time.deltaTime instead of Time.time also;

Hope this helps :slight_smile:


See also;

Ah thanks.

1 Like

You’re very welcome :slight_smile:

Privacy & Terms