Issue with if true statment

Hello, I have been trying to make this code that will break down code that an user enters into a text field. The issue is that when I set a variable to true in the OnGUI method, it does not run code in the Update method that uses the if variable == true. Any help would be greatly appreciated.
Code:

public class UserInput: MonoBehaviour {

	string wordIn = "";
	string wordOut = "";

	string[] split;
	int[] blank;
	int numWords;
	
	bool newInfo = false;

	void OnGUI(){
		wordIn = GUI.TextField (new Rect (250, 20, 250, 25), wordIn, 40);
		GUI.TextArea (new Rect (250, 60, 250, 25), wordOut, 40);
		if (GUI.Button (new Rect (300, 250, 100, 30), "Enter")) {
			Debug.Log ("RAN!");
			newInfo = true;
			wordSplit(wordIn);
			wordOut = wordIn;
			wordIn = "";
		}
	}

	void wordSplit(string newString){
		//splits the input by spaces then figures out how many words it was
		split = newString.Split(' ');
		numWords = split.Length;
		//deletes any part that was just a space
		for (int d = 0; d < numWords; d++){
			if(split[d] = " "){
				Destroy(split[d]);
				numWords--;
			}
		}
	}
	
	void Update () {
		if (newInfo == true) {
			Debug.Log(numWords);
			for(int i = 0; i < numWords; i++){
				Debug.Log(split*);*
  •  	}*
    
  •  	newInfo = false;*
    
  •  }*
    
  • }*
    }
    REVISION:
    After I have posted this, I have noticed that the destroy doesn’t work on arrays… -_-’
    Any suggestions to fix this issue would also be greatly appreciated

If you are just starting out with Unity we suggest checking out the Learn section, as there exists several tutorials, documentation and live training sessions.

http://unity3d.com/learn

Specifically, if you need to learn about programming then please go through the scripting tutorials.

Line 30

if(split[d] = " "){

should be == instead of =. Right now it assigns " " to split[d] instead of comparing " " to split[d]

if(split[d] == " "){

In this case you probably wanted to use a list instead of an array as arrays are bad for adding/removing operations.

As you noticed UnityEngine.Object.Destroy can’t be used on a string. Furthermore it can’t be used on anything that isn’t a UnityEngine.Object, including primate types (int, float), scripts that don’t inherit from UnityEngine.Object, and a few unity things such as meshes.

Empty strings "" are different than the string of the space " ". Since you are splitting at every space character there shouldn’t be any spaces in your resulting code and you are probably trying to remove empty strings. To do so you could change your code to compare with the empty string split[d]=="". However it would be easier to just use StringSplitOptions.RemoveEmptyEntries, i.e.

using UnityEngine;
using System;

public class Splitter
{
    public void Split()
    {
        string originalString = "Hello world. How are you?";
        char[] splitChar = new char[] { ' ' };
        string[] result = originalString.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);

        foreach (string s in result)
        {
            Debug.Log(s);
        }
    }
}