Unity RPG Cooldown Effect on Slot


i’ve implemented cooldown for my potions. Now im just trying to figure out a way to to visually represent the cooldown. for the time being i just wanted to display a slightly translucent image on top of the slot, with the corresponding seconds left on cooldown. ActionSlotUI(or any slotUI) does not have a way to know if it has been interacted with(this being either via mouseclick or keydown). How would i approach this? currently the trigger is on the PlayerController capturing keydown.

any advise would be great

1 Like

I left the ActionStore responsible for managing the cooldown on a given slot, because both the PlayerController and the ActionSlotUI both interface with it.

When the PlayerController instructs the ActionStore to Use an item, it sets a cooldown. The same thing happens if you rig your ActionSlotUI with a mouse click. Use() during the cooldowns are rejected by ActionStore. Then in the ActionStore, I set an event OnCooldownTimerBegin(int slot, float time). The ActionSlotUI subscribes to this event and manages it’s own separate timer for the UI display.

1 Like

ah yes my cooldown is also managed by actionstore, but their individually timing & cooldown is stored on the SO so if the user move from slot1 to 2 it will not cancel the cooldown.
And ah yes using an event always forget about that.

I don’t recommend keeping it in the SO. I tried that… it created issues between sessions.
What I did was actually implement the 1st cooldown when the item was first dragged into the slot… Changing slots would actually make you need to wait longer.

what was the problem in doing that do you remember? also yea that was my initial approach but it does not fit my game. i wanted to allow users to hotswap skills and potion.

going back to

so i got the the cooldown to work if it was static number(i just hardcoded 2s cd on everything for slot). Im not quite sure how i get the exact cooldown to match what was done on ActionStore.
So what ive done so far is:

On ActionStore:
i just added an event cooldownUpdated
and called cooldownUpdated at Use() method

On ActionSlotUI
i subscribed to cooldownUpdated to a method i created called UpdateCooldown at awake(might move it later to onenabled() )
at UpdateCooldown() i implemented my simple countdown for 2s.

im just not sure how id get the cooldown second from actionstore and its current timer tick

Update: so now i’ve figured out how to add parameters to delegate events, im able to pass my said value however each slot is subscribed on awake(). which means all slot will apply the cooldown. My current idea is to just have an if to compare index. Is this the right way? cause im just not a fan of things being called but not actually doing anything.

My Event is:
public event Action<int, float> OnCooldownApplied;

ActionStore says
OnCooldownApplied?.Invoke(slot, dockedItems[index].item.CooldownLength())

The UI subscribes, and compares it’s own slot number to the int, and applies it’s cooldown accordingly.
(I do have the CoolDownLength in the ActionItem, but not the actual cooldown itself, that’s managed in ActionStore.

so my approach was:-

public delegate void SendCooldown(int index, float cooldown);
public event SendCooldown cooldownUpdated;

Call it on Use and Add

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)

            //Able to use action
            if(CooldownTimer > Cooldown)

            //Action requires cooldown
            if (CooldownTimer < Cooldown)
                CooldownTimer += Time.deltaTime;
                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;

        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

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.