大家好,我有分数和货币问题,游戏有硬币所以玩家可以收集它们所以我想要的,硬币添加到货币文本,每次我自动播放他们增加了我在游戏中获得的金币,最后加载并保存货币,所以当我重新打开游戏时,我可以看到收集的硬币没有改变
这是GameManager脚本
public Text scoreText, coinText, modifierText, hiscoreText;
private float score, coinScore, modifierScore;
public void GetCoin()
{
diamondAnim.SetTrigger("Collect");
coinScore++;
coinText.text = coinScore.ToString("0");
score += COIN_SCORE_AMOUNT;
scoreText.text = score.ToString("0");
}
这是shopPanel脚本
//test
public static int money = 0;
public Text coinsTxt;
public Text currencyTxt;
public static int totalMoney;
void Awake()
*{
currencyTxt = PlayerPrefs.GetInt ("Coins");
}*
private void Update()
{
coinsTxt.text = "Coins: " + currencyTxt;
coinsTxt.text = "" + money;
}
void TotalMoney()
{
money += totalMoney;
currencyTxt.text = "" + totalMoney;
}
硬币脚本!
public class Coin : MonoBehaviour {
private Animator anim;
private void Awake()
{
anim = GetComponent<Animator>();
}
private void OnEnable()
{
anim.SetTrigger("Spawn");
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
//CurrencyManager.gameManager.AddMoney(1);
GameManager.Instance.GetCoin();
anim.SetTrigger("Collected");
}
}
}