Quantcast
Channel: Comments and answers for "AddListener function not working?"
Viewing all articles
Browse latest Browse all 15

Answer by Icephoenix31

$
0
0
The previously listed solutions didn't seem to work for me, so here is what I came up with. My problem anyway seemed that it tried to add the listener after the button was pressed and by that time, the variables used in the button would have changed. So I made a new script that was on the Button Prefab, so I can add the function in the prefab. And when I created the Button prefab, I only need to change the variables in the script instead of changing the button. script on the Prefab where the Button is on: public int i; public MonoBehaviour mon; public void ButtonPressed() { mon.function(i); } script where I instantiate the button: GameObject obj = Instantiate(Prefab, Transform); ButtonFunction b = obj.GetComponent(); b.mon = this; b.i = variable;

Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles





Latest Images