I am working on a game in unity where a user will click a button to gain coins and clicks over a lifetime of clicking the button but the code is making the clicks go up by a lot instead of just 1 each time it is clicked like here are the values returned the first 3 clicks 247 731 2111 anybody have an idea why it produces this behavior and how i can fix it?
using UnityEngine; using UnityEngine.UI; using System.Collections; public class GameManager : MonoBehaviour { public Button clicker; public Text coinsSec; public Text ltClicks; private float baseClick = 2; private float coins = 0; private float lifeTimeClicks = 0; private float coinsPerSec; private void Start(){ UpdateTxt (); } private void Update(){ UpdateTxt (); Clicker (); } private void Clicker(){ clicker.onClick.AddListener (delegate { coins += baseClick; lifeTimeClicks++; }); } private void UpdateTxt(){ coinsSec.text = "Coins/s: "; ltClicks.text = "Lifetime Clicks: " + lifeTimeClicks.ToString (); } }