Utils/Runtime/TimeSince.cs

28 lines
645 B
C#

using UnityEngine;
namespace Utils
{
/// <summary>
/// https://garry.tv/timesince
/// </summary>
/// <example>
/// Do something after 10 seconds.
/// <code>
/// TimeSince ts;
/// void Start() => ts = 0;
/// void Update()
/// {
/// if (ts > 10)
/// Something();
/// }
/// </code>
/// </example>
public struct TimeSince
{
private float time;
public static implicit operator float(TimeSince ts) => Time.time - ts.time;
public static implicit operator TimeSince(float ts) => new() { time = Time.time - ts };
}
}