Forum rules - please read before posting.

Making a basic "health bar" using portrait.

I'd like to simulate the Health Bar from the SNES game Clock Tower or other older games like Doom and Wolfenstein 3d. What I'd like to do is create a global variable integer with the value "5" and have the portrait switch everytime the value decreases by 1(I plan to use triggers as the decreaser and perhaps have some sort of health item or event increase it back as well) So, for example, at value 5 avatar looks fine, at 4 it changes, at 3 it starts going into the red, at 2 I'd like to animate something to signify that you're almost dead, etc. What would be the best method of achieving this? I have an idea in my head of how I'd like it to work, but I'm not sure about the actual execution. As always, thank you in advance.


  • If you rely on a Component variable, you can make use of AC's "Link Variable To Animator" component to sync its value with an Animator's integer parameter.

    If you're just dealing with a one-way link from a Global Variable to a parameter, though, you can just use this simple script:

    using UnityEngine;
    public class HealthAnimator : MonoBehaviour
        public Animator myAnimator;
        void Update ()
            myAnimator.SetInteger ("Health", AC.GlobalVariables.GetVariable ("Health").IntegerValue);
  • edited November 2022

    @ChrisIceBox thanks for replying so quickly. I'm still having some issues with setting this up. Mainly with the global variable integer. What I've done instead was the following: I've set up a empty object with various imagines (the states I've previously mentioned). and I've added a global variable integer check. If value is "1-5"= make a graphic appear. And I've added a Variable Set on a trigger to add 1 (The Global variable is 0 by default). So, in theory when the player enters the trigger is should add "1" and the variable check should see that and make visibile/teleport one of the grahipcs. Problem is it doesn't seem to work. I've tried with "set valaue", "increase by value" . Nothing seems to work. As usual, thank you for taking the time to reply.

    *Also, I forgot, I need a method to increase and decrease this variable, but I can't figure out how to decrease the amount. This is required for enemies but also "health pick ups". Any tutorial you can point me to that goes in depth on Integer/Float variables that can spare you the headache of having to answer to this wall of text is also helpful.

  • How are you determining the variable's value is not changing? Do you have Show realtime values? checked in the Variables Manager?

    You can decrease the value by assigning a negative number in the Action's "+=" box.

    A tutorial that covers a similar area can be found here.

  • Yes, I have "Show runtime values" checked in variable manager (if that's what you mean) and this is my test set-up, it still doesn't work. [] <- added a screenshot of what I have set-up. I'm sure I'm missing something obvious.

  • The screenshots don't reveal anything amiss - although you needn't run your checking Actions in parallel - just string them along from the "If condition is not met" socket.

    Check that the ActionList that increases the value by 1 is running correctly. Try running it manually by clicking "Run now" in its Inspector at runtime - does that affect the variable, or cause any message to appear in the Console?

  • edited November 2022

    Sorry to keep bothering you. I've checked with "run now" at runtime, no error, I've also tested the trigger to make sure it works, and it does. It's just the variables (integers) that seem to not work for me. I'll try using an integer variable with a hotspot to see if that works.

  • It's no bother - it does look like it should all work, and I certainly can't recreate such a problem.

    What are your AC/Unity versions? Are other Variables updating as intended?

  • edited November 2022

    I've used Bool variables and they work just fine. Unity version is 2021.3.12f1 and adventure creator version is v1.75.8. Cloning my project and attempting an update, see if that will fix it.

  • edited November 2022

    @ChrisIceBox Hi there. I'm back after some trial and error and installing stuff. I've done some checks and it seems like the Integer variables are not broken, but there's some confusing stuff still occurring. I've tested it by adding a "global variable integer set = 1" to a light switch (when clicked) and added a check to a trigger (when the character goes inside the trigger and the variable is = 1, the text appears). However, the problem is I need to run this check at runtime without any interaction. Any suggestions? As always it's much appreciated, have a wonderful week end.

  • I'll be adding the option for the Link Variable To Animator component to work with Global Variables in the next release - that should allow you to update an animation based on changes to a Global Variable automatically.

    The above script should still work in the meantime, though. Is the Animator's "Health" parameter not syncing with the variable?

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.