Struct Timer
Provides a simple interface for measuring elapsed time in seconds
Namespace: Atlas
Assembly: Atlas.Runtime.dll
Syntax
public struct Timer
Examples
using UnityEngine;
namespace Atlas.Examples
{
public sealed class Example_Timer : MonoBehaviour
{
// create a timer that ticks based on Unity's Time.unscaledTime
private Timer m_timer = new Timer( TimeScale.Unscaled );
private void Start()
{
// start timing
m_timer.Start();
}
private void Update()
{
// check if 3 seconds has passed since starting
if ( m_timer.HasElapsed( 3.0f ) )
{
// stop timing
m_timer.Stop();
}
// Toggle pause
if ( Input.GetKeyDown( KeyCode.Pause ) )
{
if ( m_timer.IsPaused )
{
m_timer.Unpause();
}
else
{
m_timer.Pause();
}
}
}
}
}
Constructors
| Improve this Doc View SourceTimer(TimeScale)
Constructor
Declaration
public Timer(TimeScale scale = TimeScale.Scaled)
Parameters
Type | Name | Description |
---|---|---|
TimeScale | scale | Target time scale to "tick" with |
Properties
| Improve this Doc View SourceElapsed
Amount of time that has elapsed (in seconds) since Start() was last
called, or 0 if it the timer has not been started
Declaration
public float Elapsed { get; }
Property Value
Type | Description |
---|---|
System.Single |
IsPaused
Whether or not the timer is currently paused
Declaration
public bool IsPaused { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsTiming
Whether or not the timer is currently measuring time
Declaration
public bool IsTiming { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceHasElapsed(Single)
Helper function to determine if the timer's elapsed time is greater or equal to the given time
Declaration
public bool HasElapsed(float time)
Parameters
Type | Name | Description |
---|---|---|
System.Single | time | Amount of time to compare with |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not the given amount of time has passed |
Pause()
Pauses timing
Declaration
public void Pause()
Start()
Starts timing
Declaration
public void Start()
Start(Single)
Starts timing, but starts at the given time offset instead of 0
Declaration
public void Start(float timeOffset)
Parameters
Type | Name | Description |
---|---|---|
System.Single | timeOffset | Amount of time to start offset by |
Stop()
Stops timing
Declaration
public void Stop()
Unpause()
Unpauses the timer
Declaration
public void Unpause()