- Home /
GUI.RepeatButton funcionality with new Unity UI (4.6.x)
Hi,
How can I achieve the GUI.RepeatButton functionality with the new Unity UI Buttons?
Answer by ina · Jun 01, 2015 at 03:27 AM
Add a Event UI component that tracks when the pointerUp/Down is true/false to your button:
1) Component > Event > Event Trigger
2) Once you are on the component: Click add Pointer Down Pointer Up
Both are PointerEventData
3) Have these booleans operate on the boolean for repeatbutton (or buttondown)
thanks, that was an old question from me I even forgot about it and I hope it will help to people who come here with google searches.
Answer by ChaosPixy · Dec 28, 2014 at 08:01 PM
Although not technically a repeat button, you could create a button that toggles a Boolean.
Then in your Update() method execute code conditionally base on your bool value.
Click the button the first time will start the desired behavior and clicking it again will stop it.
private bool isIncrementCounter = false;
void Update ()
{
if (isIncrementCounter)
{
IncrementCounter();
}
}
//Attach this method to your onClick event for your button...
void IncreaseCounterButton_onClick()
{
isIncrementCounter = !isIncrementCounter;
}