【发布时间】:2016-05-26 11:53:12
【问题描述】:
我试图在我的游戏中实现一个评分系统。我有两个变量,
public int maxScore;
public int currentScore;
要设置 currentScore,我得到 maxScore 并将其放入 currentScore:
currentScore = maxScore;
因此,如果玩家开始游戏,他将获得最大的分数。如果他现在要放慢速度,我会降低 currentPoints per Second with
IEnumerator CurrentScore()
{
currentScore -= 1;
yield return new WaitForSeconds(5); //I'm using 5, because 1 does not equals a second
}
并通过说来调用它
StartCoroutine(CurrentScore());
如果我现在查看游戏,一切看起来都很好:
游戏开始时,两者都在 3000:
如果计时器运行到特定值,则 currentScore 减少,但 MaxScore 保持不变。应该这样:
然而,一旦 WinScreen PopsUp,两个值都开始迅速下降,而不是只有一个下降:
我已将此脚本附加到显示当前(已获得)积分和可能积分的文本中:
using UnityEngine;
using UnityEngine.UI;
public class WinScreenScore : MonoBehaviour {
//Load the classes
public GameManager manager;
//To get our Text
//public GameObject scoreText;
Text max;
Text current;
//As soon as the Thread awakes, load the Text
void Awake()
{
max = GetComponent<Text>();
max.text = manager.maxScore.ToString();
}
void Update()
{
current = GetComponent<Text>();
current.text = manager.currentScore.ToString();
}
}
在显示当前分数(获得积分)的文本上编写脚本:
关于可能的点:
我不明白为什么在显示 Winscreen 后两个值都迅速下降。
感谢您的帮助!
【问题讨论】:
-
所以你从不分配
maxScore? -
你从哪里开始协程?
-
@gjttt1来自与协程相同的类,我的 GameManager.cs
-
我在 WinScreenScore 中分配了我的
maxScorevoid Awake()(我帖子中第一张图片下的代码)@ThomasAyoub -
也许我不清楚,问题是你何时/在哪里为
maxScore赋值?