【发布时间】:2018-04-29 13:16:44
【问题描述】:
我正在尝试所有可能的解决方案,但请看看这个。分数显示了,高分也显示了,但高分总是和分数一样。当我重新开始游戏时,分数不是0,而是和高分一样。如果你得到 6 分作为高分,那么分数也是 6 分。我希望你能明白。
我截图了。它刚刚开始,我没有击中任何敌人。分数应该是0,但是和高分一样。
这是附在敌人身上的健康脚本:
using UnityEngine;
public class HealthScript : MonoBehaviour
{
public static HealthScript instance;
public int hp = 1;
private GUIText scoreReference;
private GUIText highscoreReference;
private static int _highscore = -1;
public int highscore {
get { if (_highscore == -1)
_highscore = PlayerPrefs.GetInt("Highscore", 0);
return _highscore;
}
set {
if (value > _highscore) {
_highscore = value;
highscoreReference.text = _highscore.ToString();
PlayerPrefs.SetInt("Highscore", _highscore);
}
}
}
public bool isEnemy = true;
private static int points;
public void Damage(int damageCount) {
hp -= damageCount;
if (hp <= 0)
{
// Dead!
Destroy(gameObject);
points++;
scoreReference.text = points.ToString();
}
}
public void gameEnd() {
points = highscore;
points = 0;
}
//update from previous code
void Start()
{
scoreReference = GameObject.Find("Score").guiText;
highscoreReference = GameObject.Find("HighScore").guiText;
scoreReference.text = points.ToString();
highscoreReference.text = highscore.ToString ();
instance = this;
}
这是我的播放器脚本,该类中的游戏结束方法
void OnDestroy()
{
// Game Over.
// Add the script to the parent because the current game
// object is likely going to be destroyed immediately.
transform.parent.gameObject.AddComponent ();
HealthScript.instance.gameEnd ();
}
问题解决了。只需更改此“积分 = 高分;” TO“高分=积分;”。我不知道,但这样重要吗?我希望有人能解释一下。
【问题讨论】: