So I'm stuck on this issue and I can't find a solution for the life of me.
I'm trying to prevent double clicking on an object, but it seems that everything I try is either not reliable or straight out hacky.
Here's a very bare-bones code of what would cause a double trigger:
- We have an object with instance variable "clicked".
- On the first click we set the variable to true.
- On the second click if "clicked" is "true" we destroy the object.
What would happen however is when we click once, the code will be read in sequence, therefore setting "clicked" to "true" and destroying the object instantly.
A simple way of fixing this very example would be to move the second click event at the top so it gets checked first and that way it will prevent the double click, however this is easier said then done on a larger scale project with multiple files, functions, etc. so I label this method as "unreliable"
Second solution would be to create a tick timer and compare against that (skipping the current trigger check), this is how this version would look in code:
This method will work for most cases and on a larger scale, however to me at least it seems "hacky" and like a disaster waiting to happen. Not to mention if we start using "on click" and "on release" trigger then the click timer would simply not work, since we can hold the button down for longer than the timer.
I've played with the idea switching layers and visibility, but I'm determined that there is a better solution.
Does anyone have any clue how to tackle this problem differently?
Edit: In a way, I want "On click", "Mouse button is down" and "On release" to be treated as one entity and only one event can occur during this period.