Energy Bar Toolkit is built in a way that scripting knowledge is not needed in order to design anything. Of course if you want to make your bar value to change when some events occur, you must have a little scripting knowledge, make use of our Event System or PlayMaker tool with its integration package.

You must know that Energy Bar Toolkit is written entirely in C# and it need a little preparation to use in JavaScript or Boo project, but it’s still possible. You can read more about it here.

Basic Access

It’s as simple as it sounds. However, if you’re using Unity GUI version or NGUI version you need to access component called EnergyBar.

EnergyBar bar = barGameObject.GetComponent<EnergyBar>();

The simplest way to set bar value is to use ValueF property. It accepts values from 0.0 to 1.0 regardless of min and max value of bar. Setting bar value as float is helpful when minimum and maximum bar value are not important and your bar must be filled to specified % value.

bar.ValueF = 0.7f;

Of course if you want to set bar value as raw integer you can do it too. You will do this when minimum and maximum value are important and so current value must be precise; the number of health hearts for instance.

bar.valueCurrent = 25;

Setting Value Min and Value Max

You may need to change minimum and maximum value of your bar. You can do this using valueMin and valueMax fields. The change may be needed when your character powers up for instance.

bar.valueMin = 0;
bar.valueMax = 10;

Renderer Access

In some cases you may want to get access to renderer properties. Some renderers have very specific properties, but all of them extend EnergyBarBase class in which you can find most common properties.

EnergyBarBase baseRenderer = barGameObject.GetComponent<EnergyBarBase>();
baseRenderer.position = new Vector2(100, 100);

Here’s the inheritance hierarchy:

  • EnergyBarBase – the base for all renderers
    • EnergyBarOnGUIBase – base for all OnGUI renderers
    • EnergyBarMeshBase3DBase – base for all Mesh renderers