【发布时间】:2017-04-26 10:49:50
【问题描述】:
我有一个场景,我写下了我的球员统计数据。在下一个场景中(基本上在接下来的2个场景中但没关系)我想买一些武器并改变变量。
问题是我正在使用“DontDestroyOnLoad”保存对象,当我进入下一个场景时,我想知道如何更改变量。
第一个场景:
代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class statsTextsToDisplayAndChanges : MonoBehaviour
{
public static statsTextsToDisplayAndChanges _INstance;
buyWeapons bw;
public Text m_LevelText;
public Text m_AttackText;
public Text m_DefendText;
public Text m_MoneyText;
public int level = 0;
public int money = 500;
public int health = 400;
public int attack = 10;
public int def = 5;
string answer;
string url = "http://alex3685.dx.am/display.php";
public int sword1 = 200;
public void Start()
{
_INstance = this;
DontDestroyOnLoad(this.gameObject);
display();
}
public void display()
{
m_LevelText.text = level.ToString();
m_AttackText.text = attack.ToString();
m_DefendText.text = def.ToString();
m_MoneyText.text = money.ToString();
}
public void onPurchase()
{
if (money >= sword1)
{
Debug.Log("YOU BOUGHT IT");
money -= sword1;
//Destroy(GameObject.Find("playerStats"));
display();
}
}
}
第二幕:
当我按下按钮时,购买功能中的 debug.log 有效,但文本中没有任何变化(从 500 个硬币 - 200 个硬币的剑 = 300 个硬币)。
有什么想法吗?
提前致谢。
【问题讨论】:
-
请展示您迄今为止的研究/调试工作。请先阅读How to Ask页面。