Description
The Relative
property of the TimeSince
struct provides the time that has passed since the last reset, measured in seconds. This property is useful for tracking elapsed time in a straightforward manner, allowing developers to easily determine how much time has passed since a specific event occurred.
Usage
To use the Relative
property, you typically initialize a TimeSince
variable to zero when an event occurs. The Relative
property will then automatically update to reflect the time elapsed since that initialization. This can be particularly useful for timing events or implementing cooldowns in a game.
Example
// Example of using TimeSince.Relative
TimeSince timeSinceLastAction = 0;
// In an update method or similar
if (timeSinceLastAction > 5.0f)
{
// Perform an action if more than 5 seconds have passed
DoSomething();
// Reset the timer
timeSinceLastAction = 0;
}