How to create a linear timer for your Unity game? Simple Unity 2D tutorial.
Автор: Alexander Zotov
Загружено: 2017-08-31
Просмотров: 53859
#UnityTutorial #SimpleUnityGame #unitytimer #unitycountdowntimer
I play games here - / zzotoff
You are very welcome :-)
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.patreon.com/alexanderzotov
or here
https://www.paypal.me/AZotov
Thank you)
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.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: