Godot Version
Godot 4.6.2
Question
I want to make a visual component for the spell’s cooldown. The cooldown is 1 second. The problem is that when the spell is ready to use, the visual shows that only 10-20% is ready.
func cd_vis(spell_n : int, cd_time : float):
var cd_time_plus = cd_time / 100.0
print(cd_time_plus)
if spell_n == 1:
for i in range(101):
await get_tree().create_timer(cd_time_plus).timeout
$HotBar/HotBarBG/Spell1/CD.text = str(i) + "%"
if spell_n == 2:
for i in range(101):
await get_tree().create_timer(cd_time_plus).timeout
$HotBar/HotBarBG/Spell2/CD.text = str(i) + "%"
if spell_n == 3:
for i in range(101):
await get_tree().create_timer(cd_time_plus).timeout
$HotBar/HotBarBG/Spell3/CD.text = str(i) + "%"
if spell_n == 4:
for i in range(101):
await get_tree().create_timer(cd_time_plus).timeout
$HotBar/HotBarBG/Spell4/CD.text = str(i) + "%"
if input_button == "Z" and !cd_spell1_flag:
cd_spell1_flag = true
if core.Spell1.mellee:
mellee_attack(core.Spell1)
input_button = null
if !core.Spell1.mellee:
long_attack(core.Spell1)
input_button = null
core.inv_way.cd_vis(1, cd_spell1)
await get_tree().create_timer(cd_spell1).timeout
cd_spell1_flag = false