我对提高太空侵略者克隆的得分有疑问。我有2个错误。
资产/脚本/ScoreManager.cs(26,12):错误CS0103:名称 “ retryLevel”在当前上下文中不存在
资产/脚本/ScoreManager.cs(55,43):错误CS1061:类型
int' does not contain a definition for
“字符串”且没有扩展方法 可以找到Tostring' of type
int'。您是否缺少大会 参考?
我应该在哪里更改脚本的什么地方?
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;
}
}
}
答案 0 :(得分:0)
这些错误很简单:
您的代码不包含函数retryLevel
的定义,也看不到任何可用于从其他类导入这样的函数的静态方法(它是{{的继承函数1}}?您确定它没有按照C#标准的大写首字母吗?)
您有MonoBehaviour
和小的Tostring
。应该是S
。