Posted on



#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.patreon.com/alexanderzotov
or here

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.

Nguồn: https://twentyfiveautumn.com/

Xem thêm bài viết khác: https://twentyfiveautumn.com/game/

27 Replies to “How to create a linear timer for your Unity game? Simple Unity 2D tutorial.”

  1. Hey Alexander, another great tutorial and Thank you! I am having trouble making the bar fill up instead of going down… i tried :
    timeLeft += Time.deltaTime;

    timerBar.fillAmount = timeLeft – maxTime;
    and it worked to fill up but just goes same speed no matter what i set maxTime to.
    what is the correct math for this to fill up?

  2. hay I have tried to apply it to every scene, but why when the timer reloads it doesn't work, can you help me?

  3. short tutorial, simple as can be, and i understand more then in any other tutorial…
    thank you very much zotov you're the best

  4. Awesome video. I have one question, can you show/describe for me how you got Linear timer and after that, you took linear timer into source image. Because I watched your video multiple times and I couldn't get it.

  5. Great video. However, I have a question. How can I get linear Timer because I tried multiple times and I couldn't get it.
    Keep up the good work.

Leave a Reply

Your email address will not be published. Required fields are marked *