Search Unity

Add method via code in the delegate Button.onClick

Discussion in 'UGUI & TextMesh Pro' started by Luiz_Thiago, Aug 25, 2014.

  1. Luiz_Thiago

    Luiz_Thiago

    Joined:
    Feb 27, 2013
    Posts:
    32
    Hello everybody.

    I am creating a procedural way buttons, but I can not add methods in the delegate Button.OnClick ... Unity does not return me error, simply the method (public, void, and without parameters) is not added ...

    Code (csharp):
    1.  
    2. public void SetupButton () {
    3.   var button = transform.GetComponent<Button>();
    4.   button.onClick.AddListener(ButtonClicked);
    5. }
    6.  
    7. public void ButtonClicked () {
    8.   _buildStructureGUI.SelectedPool = _structurePool;
    9. }
    10.  
     
  2. Luiz_Thiago

    Luiz_Thiago

    Joined:
    Feb 27, 2013
    Posts:
    32
    Ok guys, forget...

    Worked, but is not showing in the Editor ...