Forum rules - please read before posting.

Feature request: GUI element- Gauge

edited April 2014 in Engine development
I'm trying to think about how I can create a health/stamina gauge in the GUI based on the current health variable / max health variable for instance, and the best I can come up with now is to use scene objects and the 3D menu framework. 

However, if I want this gauge to show up in every scene it would be a bit of a hassle to have to add those gauge objects to each scene, so some option to do that in the menu manager would be nice. 

To be specific, all I want is a simple bar whose horizontal size increases/decreases depending on the relationship of two variables. Nothing more complex than that... even allowing us to base menu element size on variables should be enough to get what I'm after. Thanks!

Comments

  • You could write a very simple script to adjust the size of an element based on a variable's size:

    PlayerMenus.GetElementWithName ("StatsMenu", "HealthBar");

    will return an element called HealthBar in a menu called StatsMenu.  You can adjust the width of the element with it's slotSize.x variable.  To base it on that of a Variable value, you need the variable ID, which is to the left of it's name in the Variables Manager.  I'll make things easier in the next update, but this function will return the value of an integer variable:

    int GetIntValue (int ID)
    {
     foreach (GVar _var in GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeVariables>().localVars)
     {
      if (_var.id == ID)
      {
       return _var.val;
      }
     }
     return 0;
    }
  • Ah thanks, that is a lot more straightforward than I thought it would be! The only thing left to figure out is where to put or attach this script, but I think I can do that on my own easily enough. Thanks!
  • This is just what I need. Where would I attach such a script?
  • Old code!  Actually this shouldn't be needed anymore - Slider menu elements can be linked to the value of a Global Float Variable.  This can either be a basic slider made with AC's Menu system, or a Unity UI slider for more style options.  See this tutorial on how to link Unity UI objects to the Menu system.
  • All of a sudden I'm needing something like this for my mobile game, but, I'll need to be able to show both the bar and the current HP in numbers. How would I get the bar to represent the full value of another Variable? (in this case the Health points in a number format, e.g.:0-550). Is there a way to link the float variable to my Max HP? So that I can show both the health bar and the current HP in numbers?.
  • Good question.  I'll make an adjustment to the Variable: Copy Action that allows casting (conversion of e.g. Integer to Float), which should allow you to make use of a separate Float for the slider's display.
  • Hey, that sounds great, thanks!
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.