Logo my studio is game, portfólio is developer game

How to make a time-out timemeter within a phase in Unity games

In this very basic example, I show how to make a time-out timemeter within a stage in Unity games. 

In this unity tutorial, I use Time. Deltatime in the void Update to simulate the time in seconds.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

 public class TimeCount : MonoBehaviour {

 [SerializeField] Text InTimeText;
 [SerializeField] float timeLimit = 5, currentTime;

   void Start () {
   	currentTime = timeLimit;
   }

   void Update () {
     // teste de aplicar + tempo
     InputApplyTime();
      
     if(currentTime <= 0)
     {
     	print("gameover");
     }
     else
     {
     	currentTime -= Time.deltaTime;
     }
      
   }
   // teste de aplicar + tempo
   public void InputApplyTime()
   {
     if (Input.GetButtonDown("Jump"))
     {
       ApplyTime(20);
     }
   }

   public void ApplyTime(float time)
   {
   	currentTime += time;
   }

}

Make contact!

Did you like this content? Let's talk...

I'm a game developer, I use unity. If you want to develop something, tell me!