Making a hit meter

Hello

I’m making a game where when the player attacks, an “attack meter” shows up on the screen. The player would have to click this attack meter object when its pointer is in the middle, preferably (Imagine a golf game). The damage dealt to the enemy will be proportional to the distance the meter’s pointer is from the middle, based on the animation.

This attack meter could be a rectangle with a sliding pointer or it could have curves, so I think simply calculating the distance between the pointer and the middle of the meter won’t work as intended.

Something like this (random image from google images):
85882-meter-example.jpg

My question is: what is the best way to do this?

Currently I’m getting the normalized time from the pointer’s Animator component, like so

pointerAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;

and then getting the animation length and doing some math to find how close the pointer’s animation is from its middle. But this seems kind of hackish to me, it doesn’t feel right.

Do you have any suggestions?

I use uGUI methods. So for example, in my game I have a loading screen with a loading bar. As progress continues it fills the bar. the fillamount is between 0-1. So in your class you’d define something like:

public Image imageComponent;

and then have a method similar to this one:

public void SetProgress(float amount)
    {
        if (imageComponent != null)
            imageComponent.fillAmount = amount;

        //This is if you wanted to use a text component. if so in your class declare 'public Text textComponet;
        //if (textComponent != null)
            //textComponent.text = (amount * 100).ToString("0") + "%";
    }

In the public imageComponent in the inspector you would drag and drop an image that represented the bar as if it was 100% complete. fillAmount will take care of “filling it up” in a range from 0-1. So amount would need to be a float.

If you wanted it to work like a Health bar, then in Awake() you could define it as

SetProgress(1);

so it’s completely filled and then subtract in decimals amount how much HP they lose until it becomes Zero, then they die.

HTH’s!