PurrNet
  • 🐈Introduction
    • ‼️Unique to PurrNet
    • 💲Pricing
    • 💻Compatibility
    • 📚Addon library
    • 🗺️Roadmap
    • 🏎️Performance
      • RPC Benchmarks
      • Network Transform benchmarks
    • 🥰Support PurrNet
  • 📚Guides
    • Installation/Setup
    • Getting Started
    • Converting to PurrNet
      • Converting from Mirror
      • Converting from FishNet
    • Lobby System
    • Networking custom classes, structs & types
    • Chat system with broadcasts
    • Easy Multiplayer Physics (input Sync)
  • 🎮Full game guides
    • 🔫First Person Shooter
    • 🪓Survival Game
  • 🖥️Systems and modules
    • Network Manager
      • Network Rules
      • Network Prefabs
      • Network Visibility
        • Distance condition
      • Transports
        • Composite Transport
        • UDP Transport
        • Web Transport
        • Local Transport
        • Steam Transport
        • Purr Transport
      • Authentication
    • PlayerID (Client connection)
    • Network Identity
      • NetworkBehaviour
      • Ownership
      • Sync Types
        • SyncVar
        • SyncList
        • SyncArray
        • SyncQueue
        • SyncDictionary
        • SyncEvent
        • SyncHashset
        • SyncTimer
      • Don't destroy on load
    • Network Modules
    • Collider Rollback
    • Client Side Prediction
      • Overview
      • Predicted Identities
      • Predicted Hierarchy
      • Best Practices
      • Input Handling
      • State Handling
    • Plug n' play components
      • Network Transform
      • Network Animator
      • Network Reflection (Auto Sync)
      • State Machine (Auto Networked)
    • Spawning & Despawning
    • Remote Procedure Call (RPC)
      • Generic RPC
      • Static RPC
      • Awaitable RPC
      • Direct Local Execution of RPCs
    • Instance Handler
    • Scene Management
    • Broadcast
  • 🤓Terminology
    • Early Access
    • Channels
    • Client Auth/Everyone (Unsafe)
    • Host
    • Server Auth (Safe)
  • 💡Integrations
    • Dissonance
    • Cozy Weather
Powered by GitBook
On this page
  1. Systems and modules
  2. Network Identity
  3. Sync Types

SyncTimer

The SyncTimer allows for easy synchronizing of a timer automatically counting down.

You can easily do actions such as starting, stopping, pausing and resuming the timer. Most methods accessible should be quite self-explanatory.

The SyncTimer also automatically handles reconciliation of the timer, meaning that it will force align all clients to ensure de-syncing doesn't happen. The more frequent, the more precise it will be, but the more data is used. Generally it is very data light, so don't fear for making the number lower if necessary.

Below is an example usage of the SyncTimer being server authorized (default) and having a reconcile interval of 3 (default)

public TMP_Text timerText;

//false = OwnerAuth
//3 = Reoncile interval
//The reconcile interval deciphers how often it will force align all clients
private SyncTimer timer = new();

private void Awake() 
{
    //onTimerSecondTick is called every 1 second
    timer.onTimerSecondTick += OnTimerSecondTick;
}

protected override void OnSpawned(bool asServer)
{
    //This starts the timer with 30 seconds countdown
    if(isOwner)
        timer.StartTimer(30f);
}

private void OnTimerSecondTick()
{
    //You can also get .remaining to get the precise float value
    //For displaying timers, the remainingInt makes it easy
    timerText.text = timer.remainingInt.ToString();
}

private void PauseGameTimer() 
{
    //Pauses the timer and will sync the remaining time because it's set to true
    timer.PauseTimer(true);
}

private void ResumeGameTimer()
{
    //Will resume the timer from where it was paused
    timer.ResumeTimer();
}
PreviousSyncHashsetNextDon't destroy on load

Last updated 5 months ago

🖥️