Search Unity

Question Cannot implicitly convert type 'void' to 'UnityEngine.UI.Button.ButtonClickedEvent'

Discussion in 'UGUI & TextMesh Pro' started by luuqe, Feb 9, 2022.

  1. luuqe

    luuqe

    Joined:
    Jan 21, 2022
    Posts:
    11
    Code (CSharp):
    1. shopItemTranform.GetComponent<Button>().onClick = TryBuyItem(cubeType);
    Code (CSharp):
    1.     public void TryBuyItem(CubesFactory.CubeType cubeType)
    2.     {
    3.         _shopCustomer.BoughtItem(cubeType);
    4.     }
     
  2. ZingZangGames

    ZingZangGames

    Joined:
    Dec 11, 2020
    Posts:
    73
    Do following instead:
    Code (CSharp):
    1. shopItemTranform.GetComponent<Button>().onClick.AddListener(() => TryBuyItem(cubeType));