Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

UIButton add Clickable later on

Discussion in 'UI Toolkit' started by mrSaig, Jul 5, 2019.

  1. mrSaig

    mrSaig

    Joined:
    Jan 14, 2010
    Posts:
    37
    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. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    132
    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:
    37
    Thank you! this works!
     
unityunity