So I have 3 buttons at this time. 3 , 4 and 5.
What I need to do. Every time a player chooses 3 4 or 5 he will get a random word assigned to him from a .txt file
txt files are 3pointWordList, 4pointWordList and 5pointWordList, all currently inside AssetsWord Lists
if a player chose 3 points now, the next time its the player’s turn he will have to choose between the other 2 options.
My current issue is that I cant get a random word from the txt files. ChatGPT doesnt help, other questions on stackoverflow/stackexchange also didnt help.
I went with just defining each button to have a set wordListNumber inside the inspector so button 3 has wordListNumebr 3 and so on. Also after the word was selected it should be deleted from the next randomize pool.
Code that didnt work for the randomize:
int randomIndex = Random.Range(0, wordList.Count);
string selectedWord = wordList[randomIndex];
wordList.RemoveAt(randomIndex);
My CODE:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.UIElements;
public class TaskManager : MonoBehaviour
{
public int wordListNumber;
public string wordList;
public string selectedWord;
// Start is called before the first frame update
void Start()
{
if (wordListNumber == 3)
{
}
else if (wordListNumber == 4)
{
}
else if (wordListNumber == 5)
{
}
}
Its explained above.
Jill Correy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.