K
K
K1ald2021-07-03 23:30:57
Unity
K1ald, 2021-07-03 23:30:57

Random word selection from third party .txt document?

For example, there is a text document in which about 1000 or more words are stored.
It is necessary to make it so that by pressing one button, one (or two) random words are selected from all the given words.
It is intuitively clear how this should work (add the words from the dock to the array immediately after the start of the scene and read with a special random method), but I have not yet been able to find the optimal, correct (without homocode) and optimized solution for this. The maximum of what I found is a randomizer of numbers, and I need a "Randomizer of words" ..

Please, if you are not too lazy, write this code, in any case it seems to me that it will be a small and simple code .. waiting for you ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
i__egor, 2021-07-04
@K1ald

string[] txt = Resources.Load("путь до файла").ToString().Split(' ');
string txt2 = txt[UnityEngine.Random.Range(0, txt.Length)];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question