So I was doing some coding and I need to add an OnClick delegate through function, because the button is a prefab. Only to find out the documentation isn't really helping here. I've tried doing:
Documentation:UIEventListener.Get(gameObject).onClick += MyClickFunction;
My codepublic void FoodItemClicked(GameObject go)
{
Debug.Log ("Clicked");
}
for(int x = 0; x < FoodList.Count; x++)
{
GameObject clone = Instantiate(ProductListItem, ProductListItem.transform.position, Quaternion.identity) as GameObject;
SetParent (clone);
clone
.transform.localPosition = new Vector3
(0,
276 - (100 * listCount
),
0); clone.GetComponentInChildren<UILabel>().text = FoodList[x].ToString();
UIEventListener.Get(clone).onClick(clone) += FoodItemClicked; /*<- This line*/
listCount++;
}
The FoodItemClicked function is in the same script as the for loop.
As stated in the Documentation I shouldn't need to add a GameObject to the OnClick function but since it's a Void Delegate which needs a GameObject Go I figured this should be it. Now i'm getting an error message stating the following:
Assets/Scripts/Managers/Product Search/ProductSearchManager.cs(51,52): error CS0019: Operator `+=' cannot be applied to operands of type `void' and `method group'
Assets/Scripts/Managers/Product Search/ProductSearchManager.cs(51,52): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
I'm doing something wrong what I can't figure out
