Button Event System Help

Hi All,

Need some thoughts and Idea on an issue I am having. So I have a Inventory and Storage system I am trying to figure out. Instead of trying to explain it, below is a screenshot. You have the Station storage and the Ship inventory. The two arrows are used to transfer inventory from one to the other.

So I successfully have the buttons setup using Event Trigger for PointerDown and PointerUp. These then call simple functions in a script to set a bool True for PointerDown and false for PointerUp. In Update() I have the code below to do the transfer and all that jazz.

The issue I have is with the buttons itself. It works wonderfully when I click and hold down the button how ever if I try to click just once it still transfers 3 to 10 int so basically I would like to lower the sensitivity or add some delay to slow down this function to make it more user friendly. Was hoping someone had some clever ideas on how to do this, thanks!

        //Iron StorageUpdate
        if (IronToStorageDownClick)
        {
            if (inv.Iron > 0)
            {
                if (stor_Iron < stor_maxCargo)
                {
                    inv.Iron = inv.Iron - subTractby;
                    stor_Iron = stor_Iron + subTractby;
                }
            }
        }

        if (IronToInventoryDownClick)
        {
            if (stor_Iron > 0)
            {
                if (inv.Iron < shipStats.maxCargo)
                {
                    inv.Iron = inv.Iron + subTractby;
                    stor_Iron = stor_Iron - subTractby;
                }
            }
        }
public float StorageTransferDelay = 0.5f;  // Adjust this in the editor till it feels right
float currentStorageDelay = 0f;

       //Iron StorageUpdate
        if (IronToStorageDownClick)
        {
            currentStorageDelay +=Time.deltaTime;
            if (currentStorageDelay > StorageTimeDelay)
            {
                   currentStorageDelay = 0;
                   if (inv.Iron > 0)
                  {
                      if (stor_Iron < stor_maxCargo)
                      {
                            inv.Iron = inv.Iron - subTractby;
                            stor_Iron = stor_Iron + subTractby;
                     }
                }
            }
        }
        else
              // if they aren't clicking down lets make sure currentStorage is 0 for the next time
              // they do click.  Alternately you can expose a public Property of this variable
              // that your OnPointUp sets to 0 when it set IronToStorageDownClick = false;
              currentStorageDelay = 0;

Just implement the same thing for the Other Storage. Basically it just waits StorageTimeDelaySeconds before procesing the next transfer as long as the button is held down

1 Like

Perfecto! .07 seems to be the sweet spot on this for me. Appreciate the help in leading me down the correct path on this one

Glad it worked.