Amount of Upgrades?
is there a way to keep track of how many upgrades youve bought?
so this is what i did but i didnt work.
code:
using UnityEngine;
using System.Collections;
public class UpgradeManger : MonoBehaviour {
public RPB click;
public UnityEngine.UI.Text itemInfo;
public UnityEngine.UI.Text items;
public float cost;
public int count = 0;
public int clickPower;
public string itemName;
private float _newCost;
[SerializeField] private float currentAmount;
[SerializeField] private float speed;
void Update() {
itemInfo.text = "\n$" + cost;
if (count > 24) {
speed = 50;
}
items.text = count;
}
public void PurchasedUpgrade() {
if (click.money >= cost) {
click.money -= cost;
count += 1;
click.moneyperclick += clickPower;
cost = Mathf.Round (cost * 1.05f);
_newCost = Mathf.Pow (cost, _newCost = cost);
}
if (count > 24) {
speed = 50;
}
}
}
error: Assets/UpgradeManger.cs(22,23): error CS0029: Cannot implicitly convert type int' to
string' Show less
Answer by Garazbolg · Oct 12, 2015 at 10:48 AM
This error appear just because you are missing a cast. C# cannot affect a integer into a string without you telling him to. But he can add them like in your line 18.
Just change line 22 by
items.text = count.ToString();
or
items.text = ""+count;
And thats because of the way integer et chararcters are stored in memory. integer are stored as they are so 10 => 10 but characters (each letters of a String) are stored in ascii the letter 'A' = 65. So for him to have a string that say '10' you need to tell him that you got 2 letters, one is 49 ('1') and the next if 48 ('0').
Hope this helped you understand.
Your answer
Follow this Question
Related Questions
Amount of Upgrades. 1 Answer
Problem with upgrade and long numbers 1 Answer
Text Label on an existing button [C#] 1 Answer
How to patch on Windows build game 0 Answers
i want to know when player buy a upgrade double the cost of upgrade 0 Answers