Removing a TextField

void OnGUI()
    {
        if (hammerIsInRange == true)
        {
            collectMessage = GUI.TextField (new Rect (10, 10, 200, 20), collectMessage, 25);
            if(inventory.hammerIsCollected == true)
            {
                collectMessage = null;
                collectedMessage = GUI.TextField(new Rect(10, 10, 200, 20), collectedMessage, 25);
                StartCoroutine ("MessageDisappear");
                if(removeTextBox == true)
                {
                    Debug.Log ("the coroutine worked");
                }
            }
        }
    }

    IEnumerator MessageDisappear()
    {
        yield return new WaitForSeconds (3);
        removeTextBox = true;
    }

As you can see, everything functions just fine, but I am having trouble removing the textfields I create. I try setting the collectMessage to null to remove it, but that fires a NullReferenceException. How would I remove the field so it doesn’t show?

Set it to an empty string like so:

collectMessage = "";

Not sure if that is the behavior you WANT, but it won’t throw nullrefs from collectMessage…