You can load a csv with System.IO. Once you have the data loaded, you can move it into an array with string.Split. I would then suggest adding it to a HashSet for fast searching.
Dictionary has a specific meaning in C#. You don’t actually want to use a dictionary. So drop that off your search terms.
void LoadWordList(string filename, int minLength=2)
{
allWords = new List<string>();
using (StreamReader r = new StreamReader(filename))
{
string oneLine = "";
while ((oneLine = r.ReadLine()) != null)
{
// don't grab words below a minimum length
if (oneLine.Length > minLength)
{
allWords.Add(oneLine);
}
}
}
}
That’s modified from an example I found on StackOverflow. In my Awake() function I load it like this:
LoadWordList ("Assets/Resources/ospd.txt");
(You’d need to change the location of your word list, of course.)
And then when I want to see if the chosen word is actually in the list I do this:
if (allWords.Contains(chosenWord))
//do something here
Oh yeah, you can also pass in an optional “minimum length” when you load the word list – that way if you don’t want 1 or 2-letter words you just don’t load them into the list.
This worked great. Thank you! Although after importing system.io I had to explicitly call unitygame.random. not a big deal.
For some reason I thought Unity would handle it differently. Thank you everyone!