- Home /
UGUI OnClick Event!
(Unity 4.6 Beta version) UGUI OnClick() Func is Checking Once, when i click the Button UI... like Input.GetMouseButtonDown()...
I want doing check everyframe when i click the Button UI...
How can i check ButtonUI like Input.GetMouseButton()!
sorry, i cant speak english...
Comment
Answer by fafase · Oct 19, 2014 at 05:38 PM
Most simple way I can see:
public class LevelDesign : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
bool buttonDown = false;
public void OnPointerDown(PointerEventData ped)
{
buttonDown = true;
}
public void OnPointerUp(PointerEventData ped)
{
buttonDown = false;
}
void Update()
{
if(buttonDown)
{
print ("Call");
}
}
}
Side note: the OnClick event is actually called when you release the button so it would be Input.GetMouseButtonUp. It is even called after the OnPointerUp event.
Your answer
Follow this Question
Related Questions
gui.button down 2 Answers
New GUI and Inventory problem. 1 Answer
Unity 4.6 UI Button Click Animation? 4 Answers
Passing values between scripts 5 Answers
Create new GUI TextArea on click 1 Answer