#UnityTutorial #SimpleUnityGame #unitytimer #unitycountdowntimer
The BEST MECHANICAL KEYBOARD Metoo Zero for the price. I use it. And I must say that it’s perfect!
Consider purchasing my ULTIMATE UDEMY COURSE with great discount
In this video I will show you how to create a simple linear timer for your Unity game.
First I add a funny surprised face so our scene doesn’t look so empty. Next I create a new UI text game object and name it Time’s Up text. It’s kind of game over sign. Change its text field. Position it at the center of the Canvas holding Alt+Shift keys. Set alignment. Change font size. Set overflow so the text becomes visible. Change its style and color.
Next right click on Canvas and create new UI image. Drag and drop linear timer sprite to Source Image slot. Check Preserve Aspect option. Anchor it to the top center holding Shift key. Change its width and lower it a bit. I rename it to linear timer.
Now change its Image Type to Filled and set Fill Method as Horizontal.
We are going to change its fill amount through the script so let’s create new C# script named TimerScript.
In this script we use UnityEngine.UI library to have an access to UI elements. Here we have Image timeBar gameobject, public float maxTime variable which we are able to adjust in inspector, float timeLeft variable and a reference to timesUp text game object.
In Start() method we disable timesUpText game object, get timerBar game object and set timeLeft variable.
in Update() method if statement goes. So if timeLeft more than zero then we decrease its value by deltaTime and set fill amount of the timerBar to timeLeft devided by maxTime. And if timeLeft less than zero then we enable timesUp sign and set timeScale to 0 because the game is over.
Put this script to LinearTimer game object. Select Linear Timer and drag and drop Time’s Up text to corresponding slot of Timer Script component.
Hit play and see how it works.
You can support me through
www.vecteezy.com – best free vector graphics library ever!
What this video is about and what it can be used for also: unity 2d tutorial,
unity tutorial, How to create a linear timer for your Unity game, linear timer unity, countdown timer unity, timer unity, time’s up unity, game over unity, time is over unity, how to create timer unity, add timer unity game, game over timer unity, game over countdown reaches zero unity, game over time over unity, time left unity, game over time unity, time unity, learn unity fast, unity tutorial, how to make games with unity, unity how to make game, unity how to make 2d game, not as good as brackeys but good as well.
Xem thêm bài viết khác: https://twentyfiveautumn.com/game/