scripting OnClick to just affect one instance of the script.
Hi my issue is I have made a campfire prefab that can be instantiated by the player in numerous locations in world space This fire has its own script which upon activation by player raycast, there is inventory menu where wood can be added and removed. this works fine but upon more than one fire being placed in the world. the onclick listener seems to add wood to them all.
this is line i used to call button.
button.onClick.AddListener(delegate () { AddWoodfunction(); });
is there a way to have the onclick only effect the one script and not all the fires. sorry if this sounds confusing!! Thanks in advance
Answer by springwater · Oct 23, 2015 at 11:11 PM
maybe try accessing the script through an individual object..
Answer by Statement · Oct 24, 2015 at 12:32 AM
Well, you could remove the listener when you close the menu.
// Open Menu
button.onClick.AddListener(AddWoodfunction);
// Close Menu
button.onClick.RemoveListener(AddWoodfunction);
Your answer
