- Home /
is there any way to access the selection state of a button?
The IsPressed() method is what I want but it is protected and obsolete. I want to send a message while a button is pressed, not on OnClick. The ways I see are
a) to duplicate internal button code and maintain a duplicate state. I do not like this solution as it fragile and error prone as the exact specification for button states is not available and it may change.
b) writing a new button component from scratch :(
edit: to duplicate the button state I will need to implement at least IPointerDownHandler, IPointerUpHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler, IDeselectHandler and keep one or more internal states in addition to the visible button state. Yes this is doable but fragile and error prone since there is documented button state, state diagram. I am looking for something simpler and more robust than this.
I don't think you need to writing something from a scratch. You can implement IPointerDownHandler and OnPointerDown method which, I am not sure, will occur once while you pressed the button on top of the object.
Answer by Ryuuguu · Aug 02, 2018 at 06:24 AM
I rechecked and found that there are two IsPressed() methods and only 1 is obsolete. so it can be accessed by subclassing Button. so this will allow accessing isPressed(). public class ButtonExtras : Button {
public bool PubIsPressed(){
return IsPressed();
}
}
Answer by mayur7garg · Jul 20, 2018 at 08:59 AM
You can try using the OnPointerDown method.
https://docs.unity3d.com/ScriptReference/UI.Selectable.OnPointerDown.html
Your answer
Follow this Question
Related Questions
Multiple Buttons To Change UI Text 0 Answers
How do I highlight multiple buttons at once? 1 Answer
How to change a float value with UI buttons,How Can I control a character with UI buttons? 1 Answer
How to change Menu Buttons to a Selected Image and Deselected Image 2 Answers
UI button mobile - want a button drag to register as a click 0 Answers