Button AddListener Issue [FIXED]

Hey everyone

I have a little problem with a button script i’ve made basically when the button is pressed it will subtract just the item amounts required, however on click it is carrying out approximatly 800 operations per click

Is there a way around this?

Button button = tooltip.transform.GetChild(4).GetComponent<Button>();
  button.onClick.RemoveAllListeners();
  button.onClick.AddListener(delegate {StartCoroutine(Create(craft));});

IEnumerator Create(Crafts craft)
  {
  yield return new WaitForSeconds(0.1f);
  inventory.addItem(craft.itemreference);
  Resourcesubtract(craft.craftWood, craft.craftStone, craft.craftMetal);
  }

Thanks in advance

Fixed… Seemed to be a bug with unity not updating my scripts in the editor the coroutine was the fix :slight_smile:

That syntax was obsolete as of November 2007.

 button.onClick.AddListener( () => StartCoroutine(Create(craft)) );