so my approach was:-
ActionStore.cs
public delegate void SendCooldown(int index, float cooldown);
public event SendCooldown cooldownUpdated;
Call it on Use and Add
ActionSlotUI.cs
store.cooldownUpdated += UpdateCooldown;
private void UpdateCooldown(int index, float cooldown)
{
if(this.index == index)
{
Cooldown = cooldown;
CooldownTimer = 0;
}
}
private void CountdownCooldown()
{
//If no cooldown is set leave method
if (Cooldown == 0)
{
return;
}
//Able to use action
if(CooldownTimer > Cooldown)
{
ResetCooldowns();
}
//Action requires cooldown
if (CooldownTimer < Cooldown)
{
CooldownTimer += Time.deltaTime;
cooldownImage.gameObject.SetActive(true);
cooldownSeconds.SetText(String.Format("{0:0.0}", GetCooldownRemaining()) + "s");
cooldownImage.fillAmount = GetCooldownRemainingFraction();
}
}
private float GetCooldownRemaining()
{
return Cooldown - CooldownTimer;
}
private void ResetCooldowns()
{
CooldownTimer = 0;
Cooldown = 0;
cooldownImage.gameObject.SetActive(false);
}
private float GetCooldownRemainingFraction()
{
return (Cooldown - CooldownTimer) / Cooldown;
}
}
this works fine for me atm, so i stumble across the problem you mentioned with timer held on SO where it would save current runtime on the SO causing issues further down. so went with the punishable transfer slot UI.
But anyways thank you so much for helping me out of the rabbit hole. much appreaciated