This recipe shows you how to use the concepts introduced in the previous recipes to create an actor that informs other actors of the passage of time within your game.
Create a new
Actor
class calledTimeOfDayHandler
.Add a multicast delegate declaration to the header:
DECLARE_MULTICAST_DELEGATE_TwoParams(FOnTimeChangedSignature, int32, int32)
Add an instance of our delegate to the class declaration:
FOnTimeChangedSignatureOnTimeChanged;
Add the following properties to the class:
UPROPERTY() int32 TimeScale; UPROPERTY() int32 Hours; UPROPERTY() int32 Minutes; UPROPERTY() float ElapsedSeconds;
Add the initialization of these properties to the constructor:
TimeScale = 60; Hours = 0; Minutes = 0; ElapsedSeconds = 0;
Inside
Tick
, add the following code:ElapsedSeconds += (DeltaTime * TimeScale); if (ElapsedSeconds> 60) { ElapsedSeconds -= 60; Minutes++; if (Minutes > 60) { Minutes -= 60; Hours++; } OnTimeChanged.Broadcast(Hours,...