So I have already read a lot of answers but i am very very new too Unity and coding and have very little understanding… I am a graphics designer and am having a little fun with this project I have used tutorials for all my code so not sure where i am supposed too put things. Thanks for the help
Here is my scripts
[GoldPerSecond]
using UnityEngine;
using System.Collections;
public class gps : MonoBehaviour {
public UnityEngine.UI.Text gpsDisplay;
public RocksClick click;
public ItemManager[] items;
void Start (){
StartCoroutine (AutoTick ());
}
void Update(){
gpsDisplay.text = GetGoldPerSec () + " 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 this Script connected to my balance for the Updates]
using UnityEngine;
using System.Collections;
public class RocksClick : MonoBehaviour {
public UnityEngine.UI.Text gpc;
public UnityEngine.UI.Text goldDisplay;
public float gold = 0.00f;
public int goldperclick = 1;
void Update(){
goldDisplay.text = " " + gold;
gpc.text = goldperclick + " g/click";
}
public void Clicked(){
gold = gold + goldperclick;
}
}
First off, I’d recommend that you set your text when it’s updated, rather than in the method called “Update”
Change it when it’s changed, so to speak.
Besides that, check for when your value is greater than 1,000 and then divide by 1000. Keep the fraction if you want it, or format/round it off, or simply keep the integer, whatever your preference is.
Lets say the score is 3475.
(score / 1000) gives you 3.475
.tostring() makes a number into a string
.tostring(“D”) makes a number into a string with no decimal places
Thank you so much for this and yeah 1500 to 1.5k pretty much… and 1,000,000 to 1m
however where would i put this in my code, I believe i have seen that before but wherever i put it, it never did anything
It looks like you’re trying to create a cookie clicker game where you can have crazy amounts of money up to the zillions (literally). In that case, simply having a float for gold won’t cut it. Just a FYI.
But yes, you’ll want to move your text update stuff into Clicked() so it only updates when gold actually changed.
Your spot on mate I am just for fun lol and have no idea about any of this stuff! And a video told me too put it in a float how would i change it into something else mate?
And shall i move the GoldDisplay text into clicked aswell or just the if/else bits??
Pretty much everything you’ve got in the Update() function is for updating the gold display, so yes.
As for how to handle insanely large numbers, you’d pretty much have to do some special handling for this. Like a large number class that stores how many times the number was divided by 1000, plus the base amount, for example.
Or use a byte array that you can keep increasing as the number gets bigger…
System.Numerics.BigInteger is also an option, but that’s .Net 4.0 and above.