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...
- 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 that we created in the Implementing a linear heath bar recipe in the previous chapter.
- Next, we need to import the bar into our project and set Texture Type to Sprite (2D and UI) so that it can be set as Source Image in our UI components. Then click...