Why does my item change its cost to 1 whenever i buy it?
Hi i'm trying to make a idle game, but whenever i try to buy one of my items, that gives gold per second, it changes it cost afterwards to 1. Why does that happen? Here is my script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class GoldPerSec : MonoBehaviour {
public UnityEngine.UI.Text gpsDisplay;
public Click click;
public ItemManager[] items;
void Start(){
StartCoroutine(AutoTick ());
}
void Update(){
gpsDisplay.text = GetGoldPerSec() + " gold/sec";
}
public int GetGoldPerSec(){
int tick = 0;
foreach(ItemManager item in items){
tick += item.count * item.tickValue;
}
return tick;
}
public void AutoGoldPerSec(){
click.gold += GetGoldPerSec ();
}
IEnumerator AutoTick(){
while(true){
AutoGoldPerSec();
yield return new WaitForSeconds(1);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612131446im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
PlayerPrefs Problem 1 Answer
Game window gets freeze when i click on a button 0 Answers
2D Game - Move To Position and then Do Something. 0 Answers
Can you change fillAmount to a float value? 0 Answers
I need help about object defination. 1 Answer