我正在使用Unity制作一个"增量游戏",也称为"空闲游戏",我正在尝试格式化大数字.例如,当gold说到1000或更多时,它将显示为Gold: 1k而不是Gold: 1000.
using UnityEngine;
using System.Collections;
public class Click : MonoBehaviour {
public UnityEngine.UI.Text GoldDisplay;
public UnityEngine.UI.Text GPC;
public double gold = 0.0;
public int gpc = 1;
void Update(){
GoldDisplay.text = "Gold: " + gold.ToString ("#,#");
//Following is attempt at changing 10,000,000 to 10.0M
if (gold >= 10000000) {
GoldDisplay.text = "Gold: " + gold.ToString ("#,#M");
}
GPC.text = "GPC: " + gpc;
}
public void Clicked(){
gold += gpc;
}
} …Run Code Online (Sandbox Code Playgroud)