我有一个关于if和else if的问题。我想根据"score“变量从"medals”数组中设置一个图像:
if(score > 0)
{
medals[0].SetActive(true);
}
else if
(score > 2)
{
medals[1].SetActive(true);
}
else if
(score > 5)
{
medals[2].SetActive(true);
}它只显示了一张图片,铜牌。有没有更好的方法来实现这一点?
很抱歉英语不好,谢谢你的建议
我更新的代码
score += Time.deltaTime;
Scoretext.text = ((int)score).ToString();
if (PlayerPrefs.GetFloat("Highscore") < score)
PlayerPrefs.SetFloat("Highscore", score);
if (score > 3)
{
bronze.GetComponent<Image>().enabled = true;
}
if
(score > 7)
{
silver.GetComponent<Image>().enabled = true;
}
if
(score > 13)
{
gold.GetComponent<Image>().enabled = true;
}https://stackoverflow.com/questions/38274975
复制相似问题