Progress bar

So i tried to make a progress bar. I made one that work. But i do not know if this is a good way to do it… If it is a good way to do it. Maybe some people around here would find this useful.

			if(_castBarIsActive)
			{
				if(Time.time  >= _delay)
				{
					_delay += 0.01f;
					_currentSecond += 0.01f;
				}
				if(_currentSecond >= _castTime)
				{
					_castBarIsActive = false;
				}
				
				GUI.DrawTexture(new Rect(Screen.width/2 - 175, 600f, 350f, 41f), _barEmpty);
			    GUI.DrawTexture(new Rect(Screen.width/2 - 175, 600f, (_currentSecond / _castTime) * 350, 41f), _barFull);		
			}

ok so what i do with this is that i have a function that is called when a spell/ability is used. The _castTime is depending on the spell. _delay is set to Time.time at start of the call and then progressively move forward. Let me know what you think and please if you know a better way to do this. Write it down. All help is appreciated

I would suggest using IEnumerator’s for this kind of stuff. Eg:
`

IEnumerator CastSpell(float time)
{
    while(time>0.0f)
    {
       // GUI.DrawTexute stuff
        time -= 0.1f;
        yield return new WaitForSeconds(0.1f);
    }

yield return 0;
}

`

So next time you need to cast a spell just write StartCoroutine(CastSpell(1.0f));