Skip to content

Create a 30-hour display clock

Represent one simulated day with 30 displayed hours and start at displayed 15:00. The canonical clock remains at 12:00 at that position.

Prerequisites

  • A context with an enabled Time System, as in Your first context.
  • Time Mode set to Simulated before entering Play Mode.
  • A project assembly that can reference Sital.Tunal if you use assembly definitions.

Add the example

  1. Create ThirtyHourClock.cs in your project's scripts folder.
  2. Copy the following component into it.
  3. Add it to an active GameObject and assign your Tunal Context to Context.
  4. Enter Play Mode and inspect the Time System's Simulation Time and Display Time readouts.
ThirtyHourClock.cs
using Sital.Tunal.Core;
using Sital.Tunal.Enums;
using UnityEngine;

public sealed class ThirtyHourClock : MonoBehaviour
{
    [SerializeField] private TunalContext context;

    private void Start()
    {
        if (context == null || !context.Initialize())
        {
            Debug.LogError("Assign a context with an enabled TimeSystem.", this);
            return;
        }

        if (context.Time.TimeMode != TimeMode.Simulated)
        {
            Debug.LogWarning("Select Simulated mode before using this example.", this);
            return;
        }

        context.Time.SetSimulatedHoursPerDay(30);
        context.Time.SetDisplayTime(15, 0);
    }
}

Expected result

The component requests context initialization, selects 30 display hours, and sets the clock to displayed 15:00. With the clock running, the readouts continue advancing after this initial position.

Calling Initialize() again on an initialized context returns success without replaying its original initialization event. This avoids relying on the order of this component's Start relative to another ordinary script.

Source-reviewed example

The types and method signatures have been checked against Tunal and pass standalone compilation with the available Unity references. Unity import, Inspector wiring and Play Mode behavior still require validation in your project.

Common mistakes

  • Using SetTime(15, 0) for display input. That method uses canonical hours. Use SetDisplayTime for this recipe.
  • Expecting a longer physical day. Display hours do not set the simulation rate. Configure the rate separately.
  • Using a system clock. System-clock modes keep a 24-hour display.
  • Seeing another component's changes. Keep one owner for deliberate clock-setting behavior in your scene.