Search Unity

Invisible Timer

Discussion in '2D' started by bilthedude, Oct 5, 2019.

  1. bilthedude

    bilthedude

    Joined:
    Sep 15, 2019
    Posts:
    2
    Hey,

    I’ve been using unity for about a year now to make pretty basic 2D platformers and an interactive fiction game based on tutorials. An ios game I am currently designing involves an internal timer where the player taps to start a sprite animation and then taps again at a specific time to successfully complete the levels, if not a different ending will play out. I’d really appreciate any hints on how to achieve this because I really don’t know where to begin...
     
  2. coidevoid

    coidevoid

    Joined:
    Oct 26, 2017
    Posts:
    55
    Just update a timer, stop it when the players is pressing a key and compare it to the target timer you want, with like a little range, for exemple :

    Code (CSharp):
    1. void Update()
    2. {
    3.   timer += time.deltaTime;
    4.   if(Input.GetKey(KeyCode.E)
    5.   {
    6.      float difference = Mathf.Abs(timer - targetTimer);
    7.      if(difference < 0.2f)
    8.         //win
    9.      else
    10.         //lose
    11.   }
    12. }
     
    bilthedude likes this.
  3. bilthedude

    bilthedude

    Joined:
    Sep 15, 2019
    Posts:
    2
    This is super helpful! Thank you
     
    coidevoid likes this.