So I am creating my very first game (incremental), i have been for a while now but i am a beginner at Unity. I am trying to learn by trial and error and have overcome issues ive posted previously but I am now stuck again.
I have created a “GoldPerSecond” display and have it setup and working, however i now want to implement suffix’s to the numbers so instead of 1000 it will be 1k 1000000/1m and so forth. Now i figured this out previously for my menu and Gold display but with my current script I keep getting an error… I am using the same Suffix script for all my other scripts and guessing it wont work with my coding on this script.
using UnityEngine;
using System.Collections;
public class gps : MonoBehaviour {
public UnityEngine.UI.Text gpsDisplay;
public RocksClick click;
public ItemManager[] items;
public static string KMBMaker(double num)
{
double numStr;
string suffix;
if (num < 1000d)
{
numStr = num;
suffix = "";
return numStr.ToString("0.##");
}
else if (num < 1000000d)
{
numStr = num / 1000d;
suffix = "K";
return numStr.ToString("0.##") + suffix;
}
else
{
numStr = num / 1000000d;
suffix = "M";
}
return numStr.ToString("F2") + suffix;
}
void Start (){
StartCoroutine (AutoTick ());
}
void Update(){
gpsDisplay.text = [COLOR=#ff0000]KMBMaker(GetGoldPerSec)[/COLOR] () + " g/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);
}
}
}
I have highlighted my error codes with (colour code) in Void Update. I know it is too do with the “GetGoldPerSec” being an Int but not sure how to change this or change my suffix/formatting code…
The KMBMaker coding i found on here a while ago but has been the only one I figured how to use
haha my bad dude I never meant that. I Highlighted the “KMBmaker(GetGoldPerSec)” and it came up with the color code. Thats not in my script. The error is in the KMBMaker part. I know why i have the error i just dont know how to change my Script too fix it
Dude!!! All this time and all i had too do was that!
Thank you so much <333333333333333
You truly are a life saver. Ive quit this project twice now and felt like doing it again xD! Coding for beginners is soooo stressful… Appreciate that mate i really do you GENIUS!