Script messed up

Hi,

I am making a console script. At some point when inserting the script to a gameComponent it doesn’t read out the variables anymore. When i restart the game the output is totally messed up, but then when i readd the script to the object is works fine again, except for the variables.

Does this sound familiar? I am really getting tired of re-adding the script everytime i want to test.

Jan

Do you mean an editor script? In what way does the output get messed up? Perhaps you could post the code that is causing the problems - it might help make things clearer.

No the script itself doesn’t run when i restart the game, and the compiler gives no error. The script doesn’t parse the properties for the unity propertygrid, it just shows “Script” there.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Console : MonoBehaviour 
{
		/* Example level loader */
	bool menu = false;
	int consoleHeight = (Screen.height / 2) ;
	int consoleInputBoxHeight = 25;

	int  scrollWidth =20;

	int consoleMarge = 2;

	// text field 
	string textField = "";

	// needs to be global? or a function to "add" stuff
	string consoleText = "";

	int verticalScrollValue;

	Vector2 scrollViewVector = Vector2.zero;
	
	Queue history = new Queue();
	
	int maxStack = 80;
	
	float vec;
	
	void OnGUI () 
	{
		if(menu == true)
		{	
			// Make a background box
			GUI.Box (new Rect (0,0,Screen.width, consoleHeight), "Console");
	
			// 	if the previous heightVector is the same as the amount of the scrollbar, make sure it "moves"  along with the new text
			if(vec - ((consoleHeight - (consoleMarge * 3)  - 20	 ) - consoleInputBoxHeight) == scrollViewVector.y)
			{
				//calculate the new vec to make sure nothing "new"  is added that is missed
				calcVec();
				
				// change the scrollbar vector to the new text. the scrollViewVector is the size of the vec minus the height of the scrollView			
				scrollViewVector.y = vec - ((consoleHeight - (consoleMarge * 3)  - 20	 ) - consoleInputBoxHeight);
			}

			// heh double, to make sure it is done xD
			calcVec();
					
			// Begin the ScrollView
			scrollViewVector = GUI.BeginScrollView (new Rect(consoleMarge,consoleMarge + 20,Screen.width - consoleMarge * 3, (consoleHeight - (consoleMarge * 3)  - 20	 ) - consoleInputBoxHeight), scrollViewVector, new Rect(consoleMarge,consoleMarge + 20,Screen.width - (consoleMarge * 3) - scrollWidth, vec), false, true);
			
			// Put something inside the ScrollView
			GUI.TextArea (new Rect(consoleMarge,consoleMarge + 20,Screen.width - (consoleMarge * 3) - scrollWidth, vec), consoleText);

			// End the ScrollView
			GUI.EndScrollView();
			
			// the inputfield			
			textField = GUI.TextField (new Rect(consoleMarge, (consoleHeight - consoleInputBoxHeight - consoleMarge), Screen.width - consoleMarge * 2, consoleInputBoxHeight), textField);
		}
	}
	
	private void calcVec()
	{
		System.Collections.IEnumerator myEnumerator = history.GetEnumerator();
		
		consoleText = "";
		bool first = true;
				
		// loop the history queue and build up the consoleText
		while ( myEnumerator.MoveNext() )
		{
			// the first one needs no enter at first
			if(first)
			{
				first = false;
				consoleText = " >>\t"+myEnumerator.Current;
			}
			else
			{
				consoleText = consoleText + "\n >>\t" + myEnumerator.Current  ;
			}
		}
		
		// calculate the height of the TextArea for the scrollbar
		vec = GUI.skin.GetStyle("TextArea").CalcHeight(new GUIContent(consoleText), Screen.width - (consoleMarge * 3) - scrollWidth); 
	
		// if the calculated vector is smaller then the height of the scrollView, use that height instead to make sure no conflicts occur
		if(vec < (float)((consoleHeight - (consoleMarge * 3)  - 20	 ) - consoleInputBoxHeight))
		{
			vec = (float)((consoleHeight - (consoleMarge * 3)  - 20	 ) - consoleInputBoxHeight);
		}
	}

	void AddStringToConsole(string str)
	{
		if(str != "")
		{
			history.Enqueue(str);
		
			// if the history count is larger then the stack, dequeue one
			if(history.Count > maxStack)
				history.Dequeue();
		}
	}

	void Update()
	{
		if(Input.GetKeyDown(KeyCode.BackQuote))
		{
			if(menu == true)
			{
				menu = false;
			}
			else
			{
				menu =true;
			}
		}
		
		if(menu)
		{
			if(Input.GetKeyDown(KeyCode.Return))
			{
				AddStringToConsole(textField);
				textField = "";
			}
		}
	}
}