Jump to content
AwesomeFriendYT

How to make a timer that count downs?

Recommended Posts

So I am trying to make a game that involves two teams who try to get as many kills as possible in a given time. I want the time left to be displayed at the top and counts down but I'm simply not able to make a script for that.

The main problem I'm having is I can't set the value of the countdown. I have no idea what I'm doing wrong so it would be great if somebody could help tell me how to set the TEXT UI using scripting.

I'm sorry if you think it is a stupid question but I just started.

 

Share this post


Link to post
Share on other sites

Hello :) 

There is quite a lot of ways to do this, so I will just choose one of them.
First create a variable in a global storage. (you have access to global storage variables from any logic in your game, and that is really handy for timer. :) )
image.png

Be sure to check "show in object properties window, it makes it easier to set ^^

Now open object properties of global storage in the scene (just click it in the scene), and you will see the TIMER variable. Set it to lets say 60.

Add time trigger game logic, set TIME to 1, and repeat count leave on -1 (means it will run forever, makes sure to run even if you change the TIMER value :) ).

In time trigger under variables, you will find SET TIMER tile.
image.png

Connect this to the ON TRIGGER event, and set its value to TIMER - 1. 

image.png

This makes sure to reduce the timer by one, every second. :) Now create some custom UI with text, that will display the number. I named mine TIMER_DISPLAY. Make sure to check "visible to new player" option, in custom hud settings. :D

Now just find SET TEXT text widget tile and GET WIDGET tile.

image.png

We have to use FOR EACH here, to make sure it gets displayed to every single player. You can have array of players created, or use GET PLAYERS player role/team. :) 
Each item in this array is a player, so we put it to the Player field in get widget. 
Connect it up, select the custom HUD with timer, and to the "To" field just place the TIMER variable. :) 

image.png

And we are done. :) Hopefully it helps. :)

image.png

  • Thanks 2
  • Upvote 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×