在尝试编译这个猜测数字的简单控制台游戏时,我遇到了这个奇怪的错误。这在我的桌面上工作正常,但目前我正在使用我的笔记本电脑,无法编译这个工作游戏。我得到的错误是The associated script can not be loaded. Please fix any compile errors and assign a valid script.
我已经尝试从重写代码到使用更简单的方法测试它仍然无法工作。
以下是代码本身:
using UnityEngine;
using System;
//using System.Collections;
public class NumberWizards : MonoBehaviour {
// Use this for initialization
int max;
int min;
int guess;
//string userInput = "input";
void Start () {
StarGame();
}
void StarGame() {
max = 1000;
min = 1;
print ("========================");
print ("Welcome to Number Wizard");
// print ("Give a max range of numbers: ");
// userInput = Console.ReadLine();
// max = Convert.ToInt32(userInput);
//
//
// print ("Give a min range of numbers: ");
// userInput = Console.ReadLine();
// min = Convert.ToInt32(userInput);
//
// while(min == max) {
// Console.WriteLine("The ranges must be different!");
// print ("Give a min range of numbers: ");
// userInput = Console.ReadLine();
// min = Convert.ToInt32(userInput);
//
// }
max = max +1;
guess = max - min;
print("Think of a number and don't tell me. ");
print ("The highest number you can pick is " + max);
print ("The lowest number you can pick is " + min);
print ("Is the number higher or lower than " + guess);
print ("Up arrow = higher, down = lower, return = equal");
}
void NextGuess() {
guess = (max + min) / 2;
print ("Higher or lower than " + guess);
print ("Up arrow = higher, down = lower, return = equal");
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.UpArrow)) {
//print("Up arrow key was pressed");
min = guess;
NextGuess();
}else if(Input.GetKeyDown(KeyCode.DownArrow)) {
//print("Down arrow key was pressed");
max = guess;
NextGuess();
} else if(Input.GetKeyDown(KeyCode.Return)) {
print("I won");
StarGame();
}
}
}
答案 0 :(得分:1)
这是一个要检查的事项列表。
答案 1 :(得分:-1)
错误意味着您的类被称为除NumberWizards.cs以外的其他类,遗憾的是,您通常可以根据需要在C#中命名文件,如果您希望UnityEditor看到它们,则需要将MonoBehaviours放置在正确命名的文件中