2
當我試圖編譯這個猜測數字的簡單控制檯遊戲時,我收到了這個奇怪的錯誤。這在我的桌面上運行良好,但目前我正在使用我的筆記本電腦,無法讓此WORKING遊戲編譯。我得到的錯誤是The associated script can not be loaded. Please fix any compile errors and assign a valid script.
我已經嘗試從重寫代碼到使用更簡單的方法進行測試,但仍然無法工作。Unity中的C#腳本錯誤
這裏是代碼本身:
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();
}
}
}