Problem with upgrade and long numbers
1.Numbers 2.Upgrade, after upgrading once the cost changes to 0
Code:
using System.Collections;
using UnityEngine;
public class ClickUpgrade : MonoBehaviour {
public Click click;
public UnityEngine.UI.Text itemInfo;
public float cost;
public int count = 0;
public float clickPower;
public string itemName;
private float _newCost;
void Update()
{
itemInfo.text = itemName + "\nCost: " + cost + "\nPower: +" + clickPower;
}
public void PurchasedUpgrade()
{
if (click.BTC >= cost)
{
click.BTC -= cost;
count += 1;
click.perclick += clickPower;
cost = Mathf.Round(cost * 2);
_newCost = Mathf.Pow (cost, _newCost = cost);
}
}
}
glwul4p8rwofmoa6c2nnlw.png
(5.0 kB)
vanmd2dureu0-hy-iltmiq.png
(5.2 kB)
Comment
Answer by victorbisaev · Jan 31, 2018 at 08:09 PM
Please check this line:
cost = Mathf.Round(cost * 2);
So if the initial value of cost
is less than 0.5, then Mathf.Round
makes it "0".
Was it the problem you mentioned?