Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How to start a count down timer in Tiny?

Discussion in 'Project Tiny' started by SandeepKamath, Apr 3, 2019.

  1. SandeepKamath

    SandeepKamath

    Joined:
    Apr 3, 2019
    Posts:
    3
    I need to implement countdown timer of 1 min , not finding any reference materials. Also what what is the tiny equivalent of onStart method of c#?
     
  2. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Hi, SandeepKamath.
    You can create component CountdownTimer, add "RemainingTime" field to it, and set it the initial value.
    Then, you can get delta time, subtract it from the "RemainingTime" and check if it's less or equal to 0:

    Code (JavaScript):
    1. export class GameOverSystem extends ut.ComponentSystem {
    2.     public OnUpdate(): void {
    3.         this.world.forEach([game.GameOver, game.CountdownTimer, ut.Entity], (goTag, timer, entity) => {
    4.             timer.RemainingTime -= this.scheduler.deltaTime();
    5.  
    6.             if (timer.RemainingTime <= 0) {
    7.                 this.world.removeComponent(entity, game.CountdownTimer);    
    8.                 // do your stuff
    9.             }
    10.         });
    11.     }
    12. }
     
    SandeepKamath likes this.
  3. Pakor

    Pakor

    Joined:
    Feb 2, 2017
    Posts:
    32
    Last edited: Apr 4, 2019
  4. SandeepKamath

    SandeepKamath

    Joined:
    Apr 3, 2019
    Posts:
    3
    Worked like a charm. Thank you