Skip to content

Commit

Permalink
Fix to work even when Time.timescale=0f
Browse files Browse the repository at this point in the history
  • Loading branch information
nowsprinting committed Oct 9, 2024
1 parent ed96205 commit 265c0c9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Runtime/Monkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static async UniTask Run(MonkeyConfig config, CancellationToken cancellat
{
var endTime = config.Lifetime == TimeSpan.MaxValue
? TimeSpan.MaxValue.TotalSeconds
: config.Lifetime.Add(TimeSpan.FromSeconds(Time.time)).TotalSeconds;
var lastOperationTime = Time.time;
: config.Lifetime.Add(TimeSpan.FromSeconds(Time.realtimeSinceStartup)).TotalSeconds;
var lastOperationTime = Time.realtimeSinceStartup;

var beforeGizmos = false;
if (config.Gizmos)
Expand All @@ -52,7 +52,7 @@ public static async UniTask Run(MonkeyConfig config, CancellationToken cancellat

try
{
while (Time.time < endTime)
while (Time.realtimeSinceStartup < endTime)
{
var didAct = await RunStep(
config.Random,
Expand All @@ -65,10 +65,11 @@ public static async UniTask Run(MonkeyConfig config, CancellationToken cancellat
cancellationToken);
if (didAct)
{
lastOperationTime = Time.time;
lastOperationTime = Time.realtimeSinceStartup;
}
else if (0 < config.SecondsToErrorForNoInteractiveComponent &&
config.SecondsToErrorForNoInteractiveComponent < (Time.time - lastOperationTime))
config.SecondsToErrorForNoInteractiveComponent <
(Time.realtimeSinceStartup - lastOperationTime))
{
var message = new StringBuilder(
$"Interactive component not found in {config.SecondsToErrorForNoInteractiveComponent} seconds");
Expand Down

0 comments on commit 265c0c9

Please sign in to comment.