Skip to content

Commit 7d278cf

Browse files
committed
feat(timer): add loop
1 parent 72757f3 commit 7d278cf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

SharpEngine.Core/Utils/Timer.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ namespace SharpEngine.Core.Utils;
77
/// </summary>
88
/// <param name="startTime">Time of Timer</param>
99
/// <param name="endFunction">Function which be called at the end</param>
10-
public class Timer(float startTime, Action endFunction)
10+
/// <param name="loop">True if timer will loop</param>
11+
public class Timer(float startTime, Action endFunction, bool loop = false)
1112
{
1213
/// <summary>
1314
/// Start Time of Timer
@@ -24,6 +25,11 @@ public class Timer(float startTime, Action endFunction)
2425
/// </summary>
2526
public Action EndFunction { get; set; } = endFunction;
2627

28+
/// <summary>
29+
/// True if timer will loop
30+
/// </summary>
31+
public bool Loop { get; set; } = loop;
32+
2733
/// <summary>
2834
/// Update Timer with Time
2935
/// </summary>
@@ -35,7 +41,10 @@ public bool Update(float delta)
3541
if (CurrentTime <= 0)
3642
{
3743
EndFunction();
38-
return true;
44+
if (Loop)
45+
CurrentTime = StartTime;
46+
else
47+
return true;
3948
}
4049

4150
return false;

0 commit comments

Comments
 (0)