Forum rules - please read before posting.

Game-Wide Countdown Timer

Hello again! Completely different issue from yesterday.

My goal is to create a countdown timer that persists through the entire game. The timer would be displayed to the player in a persistent UI. I've got most of it working, but admittedly all through custom scripts outside of AC.

So here's my problem: I have a script that runs / persists that has a public Text element to show the timer. Ordinarily, I would just connect this to the Instantiated UI element associated with it in each scene... but AC generates the Canvas at run-time.

I attempted to plug the prefab version of the UI element into the public variable slot, but that did not work.

I assume that there is some sort of interaction I need to set up with the Menu system, but so far I have not found the combination of options that makes this viable. (I do have other UI elements running through the Menu system, so the system is not 100% foreign to me.)

Any ideas?

Comments

  • What did you do exactly in the 3rd paragraph?  I don't understand what you mean by that exactly.

    When working with Menus, it's always a good idea to first get things working in AC's built-in menu system before moving it to Unity UI - that way you can rapid prototype the functionality you want before thinking about how it looks.

    If you've written a script that sets the timer yourself, you can link this to a Menu via a Global String variable.  Create a new String Global variable in the Variables Manager and make a note of it's ID number (the number to the left of its name in the list).  You can then assign that string to that of the timer value within your script:

    GlobalVariables.SetStringValue (2, "My Timer text"); // Replace '2' with the correct ID number

    If the 'show realtime values' option is on the Variables Manager, you can confirm the link is working by viewing it while the game is running.

    You can then display the value of this variable within a Label menu element by using the variable token, which gets replaced with the variable's value in-game:

    "Time left: [var:2]"

    This token will also be listed in the Variable's entry in the Variables Manager.
  • I have learned a valuable lesson -- don't start by first going around AC and then trying to hook it up afterwards. Instead, hook the scripts up to AC first and then use AC to manage all UI elements.

    The "SetStringValue" was what I needed. I have everything working. The third paragraph isn't important now. It was derived from the idea that I should hook my script directly up to the UI instead of going through AC for coordinating all UI elements.

    Thank you again. I'm sure you'll hear from me again soon as I create more problems to solve.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.