【发布时间】:2019-02-02 12:37:31
【问题描述】:
我在增加我的太空入侵者克隆中的分数时遇到了问题。我有 2 个错误。
Assets/Scripts/ScoreManager.cs(26,12):错误 CS0103:名称 `retryLevel' 在当前上下文中不存在
Assets/Scripts/ScoreManager.cs(55,43):错误 CS1061:键入
int' does not contain a definition forTostring' 并且没有扩展方法 可以找到Tostring' of typeint'。你错过了一个程序集 参考?
我应该在我的脚本中的什么地方和什么地方进行更改?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
int i = 0;
public GameObject HighScoreDisplay;
public Text scoreDisplay;
public int score = 0;
public Text[] highScoreTables;
private void Start()
{
if (HighScoreDisplay == null || scoreDisplay == null) {
Debug.LogWarning("Values are missing on the ScoreManager!");
return;
}
retryLevel();
}
private void update()
{
scoreDisplay.text = score.ToString();
}
public void ModifyScore(int scoreToAdd)
{
score += scoreToAdd;
}
public void fromScratch(){
score = 0;
HighScoreDisplay.SetActive(false);
}
public void PlayerDied()
{
HighScores.AddScore(score);
foreach (Text table in highScoreTables)
{
table.text = HighScores.scoreTable[i].Tostring();
i++;
}
HighScoreDisplay.SetActive(true);
score = 0;
}
}
public static class HighScores
{
public static List<int> scoreTable = new List<int>{0,0,0};
public static void AddScore(int score)
{
if (score > scoreTable[2])
{
scoreTable[2] = score;
}
else if (score > scoreTable[1])
{
scoreTable[1] = score;
}
else if (score > scoreTable[0])
{
scoreTable[0] = score;
}
}
}
【问题讨论】: