- Home /
Editor GUI error
Im making a hangman game, and i need to use the EditorGUI.BeginChangeCheck function, however it requires me to put the script in an editor folder, as i have done. Now, it gives me this error "The class defined in the script is not derived from MonoBehaviour or ScriptableObject!" any help will be appreciated!
public var word : String;
static var typeArea : String[];
private var lastWord : String;
static var lastLetterSet : String[];
public var typeAreaStyle : GUIStyle;
// *****************BODY CODE AREA********************************
function Update() {
if(lastWord != word)
{
DivideTextArea();
}
//CheckIfCorrect();
}
function DivideTextArea() {
lastWord = word;
typeArea = new String[word.Length];
for(i = 0; i < typeArea.Length; i++)
{
typeArea[i] = "_";
}
}
function OnGUI() {
EditorGUI.BeginChangeCheck ();
var textPosX = 25;
var textPosY = Screen.height - 50;
lastLetterSet = new String[typeArea.Length];
for(i = 0; i < typeArea.Length; i++)
{
typeArea[i] = GUI.TextField(Rect(textPosX, textPosY, 50, 50), typeArea[i], 1, typeAreaStyle);
if(GUI.changed)
{
GUI.changed = true;
}
textPosX += 75;
if(typeArea[i] == "") //reset to underscore if area is empty
{
typeArea[i] = "_";
}
}
if(EditorGUI.EndChangeCheck())
{
CheckIfCorrect();
GUI.changed = false;
}
}
function CheckIfCorrect() {
for(i = 0; i < typeArea.Length; i++)
{
if(typeArea[i] != "_")
{
if(typeArea[i] == word[i])
{
Debug.Log("you are correct");
}
}
}
}
Comment