【发布时间】:2020-02-25 01:17:01
【问题描述】:
我有一个代码,其中有一个经验栏,在它下面有一个级别文本框和一个经验文本框。代码如下:
public Slider barraExperiencia;
public Button botonManzana;
public Text txtNumeroNivel, txtNumeroExperiencia;
void Start()
{
barraExperiencia.value = PlayerPrefs.GetFloat("Experiencia");
nivel = PlayerPrefs.GetFloat("Nivel");
botonManzana.onClick.AddListener(ButtonAlimentoClicked);
}
void Update()
{
PlayerPrefs.SetFloat("Experiencia", barraExperiencia.value);
PlayerPrefs.SetFloat("Nivel", nivel);
txtNumeroExperiencia.text = barraExperiencia.value.ToString() + "/" + barraExperiencia.maxValue.ToString();
if (barraExperiencia.value >= barraExperiencia.maxValue)
{
barraExperiencia.value = 0;
nivel += 1;
txtNumeroNivel.text = nivel.ToString();
barraExperiencia.maxValue += 100;
}
}
void ButtonAlimentoClicked()
{
barraExperiencia.value += 10;
}
在代码中,当按下按钮 botonManzana 时,它会增加条形的值。当 bar 的值达到最大值时,它返回 0,变量 nivel(级别)增加。
我想保存和加载 bar 和“nivel”的值,我已经使用 PlayerPrefs 完成了它,就像代码中显示的那样,但它不起作用。如果有人可以帮助我,请。
【问题讨论】:
标签: c# user-interface unity3d save load