SCRIPTING API / Time, input and debug / Time
Time
How much time passed: the frame time for OnUpdate, the fixed step for OnFixedUpdate, and how far the rendered frame is between two fixed steps. Values are in seconds of game time.
Kindclass
NamespaceKroys.EngineScripting
Members3
Source
Time.csEXAMPLE
In a script
The callbacks receive the same values as their argument (deltaTime, fixedDeltaTime); Time is for code outside them, such as coroutines and helpers.
Core.cs
public sealed class Blinker : EntityScript { public float Interval = 0.5f; private float elapsed; private int fixedSteps; protected override void OnUpdate(float deltaTime) { // deltaTime is Time.DeltaTime: the frame time, different every frame. elapsed += Time.DeltaTime; if (elapsed >= Interval) { elapsed -= Interval; MeshRenderer.SetVisible(Entity, !MeshRenderer.IsVisible(Entity)); } } protected override void OnFixedUpdate(float fixedDeltaTime) { // Time.FixedDeltaTime is the same every step (1/60 s by default). if (++fixedSteps % 60 == 0) Debug.Log($"{fixedSteps * Time.FixedDeltaTime:0.0} s of simulation"); } }
REFERENCE
Members
Properties
#public static float DeltaTime { get; }Time in seconds since the previous runtime update.
#public static float FixedDeltaTime { get; }Fixed timestep duration in seconds.
#public static float FixedAlpha { get; }How far this frame is between the last two fixed steps (0..1), the render interpolation alpha.
Transform.InterpolatedPosition uses it; 1 inside FixedUpdate and on the dedicated server.Signatures
public static float DeltaTime { get; } public static float FixedDeltaTime { get; } public static float FixedAlpha { get; }
KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.