Deselect chat box

how do i deselect the chat box after sending

    import Debug;

  
    private var log:Array = new Array();

    var maxLogMessages:int = 50;

    var visible:boolean = true;

    

    var stringToEdit : String = "";

    var selectTextfield : boolean = true;
    
    
	var versionShown : boolean = true;
	var vers = 0.3;
	var snapVers = 0;
         
    function Start()

    {

    	Input.eatKeyPressOnTextFieldFocus = false;
		
		if(versionShown){
        log.Add("Version: " + snapVers + "." + vers);
        	if (Debug.isDebugBuild) {
			Debug.Log ("This is a debug build!");
			print("This is a debug build!");
	}
        }else{
        log.Add("Welcome");
       }

    }

    function print(string:String)

    {

        log.push(string);

        if(log.length > maxLogMessages)

            log.RemoveAt(0);

    }

     
    private var scrollPos:Vector2 = Vector2(0, 0);

    private var lastLogLen:int = 0;

    var printGUIStyle:GUIStyle;

    var maxLogLabelHeight:float = 100.0f;

     
    function OnGUI()

    {

        if(visible)

        {

        	GUI.SetNextControlName ("chatWindow2");
			GUI.TextField (Rect (0.0, 5000, 20, 20), "", 25);
            
            if (!selectTextfield) {
            GUI.SetNextControlName ("chatWindow");
            stringToEdit = GUI.TextField (Rect (0.0, Screen.height - 50, 200, 20), stringToEdit, 25);
        	GUI.FocusControl ("chatWindow");            	
        	}
        	else if (selectTextfield == true) {
        	GUI.FocusControl ("chatWindow2");    
        	}

            var logBoxWidth:float = 180.0;

            var logBoxHeights:float[] = new float[log.length];

            var totalHeight:float = 0.0;

            var i:int = 0;

            for(var string:String in log)

            {

                var logBoxHeight = Mathf.Min(maxLogLabelHeight, printGUIStyle.CalcHeight(GUIContent(string), logBoxWidth));

                logBoxHeights[i++] = logBoxHeight;

                       

                totalHeight += logBoxHeight+10.0;

            }

       

            var innerScrollHeight:float = totalHeight;

           

            if(lastLogLen != log.length)

            {
                scrollPos = Vector2(0.0, innerScrollHeight);
                lastLogLen = log.length;
            }

            scrollPos = GUI.BeginScrollView(Rect(0.0, Screen.height-150.0-50.0, 200, 150), scrollPos, Rect(0.0, 0.0, 180, innerScrollHeight));
           
            var currY:float = 0.0;
            i = 0;
            for(var string:String in log)
            {
                logBoxHeight = logBoxHeights[i++];
                GUI.Label(Rect(10, currY, logBoxWidth, logBoxHeight), string, printGUIStyle);
                currY += logBoxHeight+10.0;
            }
            GUI.EndScrollView();
        } 

    }
      
    function Update () {

    if(Input.GetKeyDown("return")) {
    
    if(selectTextfield) {
    
    selectTextfield = !selectTextfield;
    
    }

    if(stringToEdit != "") {
    
		if (stringToEdit == "/test1")
		{
		Debug.Log("CmE4");
		selectedTextfield = true;
		stringToEdit = "";
		}
		
		if (stringToEdit == "/test2")
		{
		Debug.Log("CmE4");
		selectedTextfield = true;
		stringToEdit = "";
		}
		
		if (stringToEdit == "/timescale 1")
		{
		Debug.Log("TSC1");
		Time.timeScale = 1;
		selectedTextfield = true;
		stringToEdit = "";
		}
		
		if (stringToEdit == "/timescale 0")
		{
		Debug.Log("TSC0");
		Time.timeScale = 0;
		selectedTextfield = true;
		stringToEdit = "";
		}
		
		if (stringToEdit == "/reset") 
		{
		Debug.Log("Reset2");
		GameObject.Find("First Person Controller").transform.position = new Vector3 (0,1,-9.5);
            selectedTextfield = true;
		stringToEdit = "";
		}
		
		else
		{
		Debug.Log("Pass 1");
		log.Add("" + stringToEdit );
		selectedTextfield = true;
    	stringToEdit = "";
		}


    }


    }

    }

Without actually wanting to read through 200 lines of your commentless code, this is a way to deselect an input line, that works well for things like chat, where you want to remove the focus from the input, after the user hits enter. The way it works is a more like a word-around, but it binds a focus to the scrollbar, and when clicking enter, it then focuses this scrollbar. Since a scrollbar doesn’t have a focus, it will drop the focus totally back to the game, but in this proccess, you de-select the chat input.

Example 01: [Focus]

// ..
GUI.SetNextControlName("FocusAway");
Chat_Scrollbar = GUILayout.BeginScrollView(Chat_Scrollbar);	
// ..

// ..
if(Event.current.type == EventType.keyDown && Event.current.character == "

")
{
GUI.FocusControl(“FocusAway”);
}
// …

Related documentation: