How to adapt C# script for UGUI Health Globe

Hello all! I have right here my so far adapted code for a script (came with a GUI I bought) that I am trying to get to work for the UI.

using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UI.Tweens;
using System.Collections;

public class FillHP : MonoBehaviour {
   
    public Image imageComponent;
    public float Duration = 5f;
    public TweenEasing Easing = TweenEasing.InOutQuint;
    public float Health = 0f;
    public float MaxHealth = 0f;
   
    // Tween controls
    [NonSerialized] private readonly TweenRunner<FloatTween> m_FloatTweenRunner;
   
    // Called by Unity prior to deserialization,
    // should not be called by users
    protected FillHP()
    {
        if (this.m_FloatTweenRunner == null)
            this.m_FloatTweenRunner = new TweenRunner<FloatTween>();
       
        this.m_FloatTweenRunner.Init(this);
    }
   
    protected void Start()
    {
        if (this.imageComponent == null)
            return;
       
        this.StartTween(0f, (this.imageComponent.fillAmount * this.Duration));
    }
   
    protected void SetFillAmount(float amount)
    {
        if (this.imageComponent == null)
            return;
       
        this.imageComponent.fillAmount = amount;
    }
   
    protected void OnTweenFinished()
    {
        if (this.imageComponent == null)
            return;
       
        this.StartTween((this.imageComponent.fillAmount == 0f ? 1f : 0f), this.Duration);
    }
   
    protected void StartTween(float targetFloat, float duration)
    {
        if (this.imageComponent == null)
            return;
       
        var floatTween = new FloatTween { duration = duration, startFloat = this.imageComponent.fillAmount, targetFloat = targetFloat };
        floatTween.AddOnChangedCallback(SetFillAmount);
        floatTween.AddOnFinishCallback(OnTweenFinished);
        floatTween.ignoreTimeScale = true;
        floatTween.easing = this.Easing;
        this.m_FloatTweenRunner.StartTween(floatTween);
    }
}

Essentially all I got to so far as to add public variables Health and MaxHealth. I’m actually using Playmaker, so Health and MaxHealth are being filled every frame.

I tried changing 0f ? 1f : 0f to Health ? MaxHealth : Health but that never worked. It was filled the entire time.

Thanks in advance, going to be tinkering around with this in the meantime :slight_smile:

Sorry if this is such a simple answer, never dealth with “Filling” and image before or tweening.

I’d like if this could get deleted, but yeah it was super simple all I ended up doing was making a completely new script and doing this:

using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class FillHP : MonoBehaviour {
   
    public Image imageComponent;
    public float Health = 0f;
    public float MaxHealth = 0f;

    void Update() {
        float calc_Health = Health / MaxHealth;
        imageComponent.fillAmount = calc_Health;
    }
}

So essentially once I learn more Playermaker I’ll probably just replace this. Since I don’t think putting that in update is efficient.