using UnityEngine;
using System.Collections;

public class Timer {

    public float m_duration;
    public float m_age;
    public bool m_started;

    public void start( float duration ) {
        m_duration = duration;
        m_age = 0.0f;
        m_started = true;
    }

    public void step( ){
        m_age += Time.deltaTime;
    }

    public bool isRunning( ) {
        bool result = ( m_started && m_age < m_duration );
        return result;
    }

    public bool isEnded( ) {
        bool result = ( m_started && m_age >= m_duration );
        return result;
    }

    public bool isEndedOnce( ) {

        bool result = ( m_started && m_age >= m_duration );

        if ( result ==  true ) {
            m_started = false;
        }

        return result;
    }

    public void stop( ) {
        m_started = false;
    }

    public float getPercentage( ) {
        float percentage = Mathf.Clamp01( m_age / m_duration );
        return percentage;
    }
}
