- Home /
RepeatButton Behavior: Mouse move releases button?
I'm experimenting with code to monitor when a GUI.RepeatButton button is released. Here is the code as it currently stands:
private var transactionHold : boolean = false;
private var hasTransaction : boolean = false;
function OnGUI ()
{
if (GUI.RepeatButton(new Rect(10, 10, 200, 50)
, "My Button"))
{
transactionHold = true;
hasTransaction = true;
}
else
{
transactionHold = false;
}
}
function Update()
{
if (hasTransaction && !transactionHold)
{
print("Process transaction");
hasTransaction = false;
}
}
Case 1: I click and hold the button and don't move the mouse while the button is held down. I get one "Process transaction" message when I release the button.
Case 2: I click and hold the button, then move the mouse around while staying inside the bounds of the button. I get a whole bunch of "Process transaction" messages. While there is no visual indication of it, the button is behaving as if it is being clicked rapidly. If I stop moving the mouse, the messages stop. Move the mouse again, lots of messages.
Case 1 behavior is as expected. But can anyone explain the behavior in case 2?
[EDITED: Updated code to be more concise.]
Answer by spinaljack · May 26, 2010 at 10:57 AM
You can use your own mouse down and mouse up flags to prevent repeated activations of the button although it does sound a bit like undesired / unintuitive behaviour, perhaps you should submit a bug report.
You are probably correct. It is most likely a code or a document defect. If I don't get an explanation within a day or two I'll submit a defect.
Answer by japanitrat · May 20, 2011 at 04:18 PM
experienced the same .. one most likely needs to check the current event, i.e. check if the mouse really sent the mouse-up event.
same issue: http://answers.unity3d.com/questions/48175/guirepeatbutton-crazy.html
[Update] the event you want to check for is EventType.Used
Your answer
![](https://koobas.hobune.stream/wayback/20220613025318im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
RepeatButton Problem 1 Answer
GUI.repeatbutton crazy? 1 Answer
Android: GUI.RepeatButton only working when I lift my finger 0 Answers
OnGUi.RepeatButton true/false problem 1 Answer
GUI Button for android? 1 Answer