Search Unity

UIButton add Clickable later on

Discussion in 'UIElements' started by mrSaig, Jul 5, 2019.

  1. mrSaig

    mrSaig

    Joined:
    Jan 14, 2010
    Posts:
    29
    Im trying to generate my View in a seperate class and let the controller do all the binding and stuff
    so my problem is that when i assing a clickable action on button create like this:

    Code (CSharp):
    1. var btn = new Button(ActionMethod);
    then the Action is called like it should

    but when i create a Button like this

    Code (CSharp):
    1. var btn = new Button();
    2. btn.clickable = new Clickable(ActionMethod);
    nothing happens, even when i add this line

    Code (CSharp):
    1. btn.AddManipulator(btn.clickable);
    nothing. (I Saw this last line in the constructor of Button)

    I dont get what i'm doing wrong here!
     
  2. UnityMat

    UnityMat

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    26
    This api will be improved in the future. For the moment, you can try:
    btn.clickable.clicked += ActionMethod;
     
    mrSaig likes this.
  3. mrSaig

    mrSaig

    Joined:
    Jan 14, 2010
    Posts:
    29
    Thank you! this works!