- Home /
Question by
kurpnieks2 · Jul 16, 2016 at 08:53 AM ·
buttonbuttonsonclick
onClick.Add() with argument
Hello,
Basically I have 2 buttons that i want to add one function to but make the function give different results on clicking both buttons. Here is what I have tried so far:
ButtonA.onClick.AddListener (delegate {DisplayNumber(3);});
ButtonB.onClick.AddListener (delegate {DisplayNumber(6);});
void DisplayNumber(int i){ Debug.Log(i); }
The problem is when I click ButtonA, the result I get is 6 since it simply overwrites the value.
Is there a way I can get number 3 when I click the first button and 6 when I do the same with other button?
Thanks.
Comment