Creating a linear timer

In this recipe, we are going to create a linear timer. In this instance, the timer is shown as a long bar that shortens over time. An example of this would be when we want a player to make a decision within a short period of time, such as during a dialog choice to progress the narrative. In this case, the timer may feature above or even below the choices to indicate the amount of time that the player has left to decide. To achieve this, we will use the Image (Script) component and develop a script to manage the length of the bar according to the time remaining.

How to do it...

  1. First of all, we need to create a bar for our timer. To do this, we can open a graphics program to create it. Alternatively, we can just use the bar ...

Get Unity UI Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.