button click() requires 2 clicks to work
I have a simple button that i have added the function MouseDown() in a javascript in the inspector. The rollover works fine , the press color works fine, but the MouseDown() function in my script gets called only on a second mouseclick. What could be the cause?? What should I look for?
Answer by bartekwilk315 · Feb 01, 2021 at 10:10 PM
I know this is very old question, but I'll answer, for other programmers. Better practice is to use "OnPointerDown" method from UnityEngine.EventSystems, for UI elements. If that won't work, try to find answer in your code. I had a similar behaviour: My code had a boolean value, set to true on start, when "OnPointerDown" method started I negated a value of boolean (here from true to false), and checked whether boolean is true, and then performed an operation. If you set your boolean to true at start, and later change its value, button will detect, that value is now false (If you created button system from nothing).