In our Unity timer post, we had discussed about creating various types of timers in Unity with C# code. In this tutorial, we will see how to create a countdown timer using visual scripting in Unity and display the timer on to the game scene.
Creating the game objects
- Add an empty gameobject called timer.
- Add a text gameobject. This will add a canvas and event system to your scene.
- Add a script machine component to the timer gameobject and create a new flow graph.
- Let’s called the flow graph timer_graph.
- Add a variable of type gameobject to timer and drag and drop your text gameobject to it. Name it Timer_display.
Creating the graph logic
- Add a timer, get variable, float to string and a set text block.
- There are many types of float to string block. Add the one with format option.
- Set the duration for the timer.
- Set the format you want in the float to sting block.
- Select the variable timer_display in the get variable block.
- Connect the graph as shown in the image below.