Image FillAmount not filling?

Hello everyone, for the cooldown of the skills in my game, Im creating UI icons that shows the chosen skill and the cooldown time so you can use it again.
What Im trying to do is quite simple:
Step 1: The skill blue circle is full, meaning that the skill is charged and ready to use. (See first circle in the image).
Step 2: After using the skill the circle gets empty. (Second circle in the image).
Step 3: The circle starts to fill again, meaning that the skill was used but will be ready to use when the circle is full. The cycle starts again.

But the problem is, after emptying the circle (Step 2), my current script cant fill correctly, it stays empty forever, like the second circle in the image. Script:

public JumpPlayer jPlayer;

    public Image coolDownImage;
    float cooldownT;
    bool isCooldown;

	// Use this for initialization
	void Start () {
        cooldownT = jPlayer.coolDown;
	}
	
	// Update is called once per frame
	void Update () {
        if (jPlayer.coolDownIcon == true) {
            coolDownImage.fillAmount = 0;
            coolDownImage.fillAmount += 1 / cooldownT * Time.deltaTime;
            print(coolDownImage.fillAmount);

            if (coolDownImage.fillAmount >= 1) {
                coolDownImage.fillAmount = 1;
                jPlayer.coolDownIcon = false;
            }
        }
	}
}

Printing the fillamount shows that it sits between 0.0004-0.0005 forever. If I do it in a way that the circle starts empty, after shooting it goes full and make its way to 0 again, it works, but I cant figure how to implement the 3 steps shown above, I thought this script would work but I guess there are some mathematical problems there :s
Thanks in advance!
129271-excluir9.png

I made this really quick. I think its a bit more simplified and easier to grok what is happening. You should be able to take it and retro fit it into what you are doing.


using UnityEngine;
using UnityEngine.UI;


/// <summary>
/// Attach to skill image
/// </summary>
public class Skill : MonoBehaviour
{
    [SerializeField] Image skillImage;          // Reference your image
    [SerializeField] float refreshRate = 1f;    // Rate of refresh

    public bool SkillReady { get { return skillImage.fillAmount >= 1f; } }


    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) && SkillReady)
        {
            // Set fill amount to zero
            skillImage.fillAmount = 0f;

            // Do skill things
        }

        // Refresh skill
        if (SkillReady == false)
        {
            skillImage.fillAmount += refreshRate * Time.deltaTime;
        }
    }
}

You’re resetting it every time with:

coolDownImage.fillAmount = 0;
coolDownImage.fillAmount += 1 / cooldownT * Time.deltaTime;

So, this fill amount will always just be whatever 1 / cooldownT * Time.deltaTime happens to evaluate as. If your goal is to have 0 fill whenever your cooldown resets, I imagine your solution is going to look a lot like this:

void Update () {
	if (jPlayer.coolDownIcon == true) {
		coolDownImage.fillAmount += 1 / cooldownT * Time.deltaTime;
		print(coolDownImage.fillAmount);
	
		if (coolDownImage.fillAmount >= 1) {
			coolDownImage.fillAmount = 1;
			jPlayer.coolDownIcon = false;
		}
	} else {
		coolDownImage.fillAmount = 0;
	}
}

Image Type has to be “Filled”, otherwise the fillAmount will be ignored and always be considered = 1.