I have a script for random word generating:
public TextMeshPro largeText;
public void BtnAction()
{
CreateRandomString();
}
private void CreateRandomString(int stringLength = 10)
{
int _stringLength = stringLength - 1;
string randomString = "";
string[] characters = new string[] { "A", "B", "C", "D" };
for (int i = 0; i<= _stringLength; i++)
{
randomString = randomString + characters[Random.Range(0, characters.Length)];
}
largeText.text = randomString;
}
In my game, the player has to collect letters, which I have made with a tag of collectables, to use in the inventory system for gathering.
private void OnTriggerEnter2D(Collider2D other)
{
if(other.CompareTag("Collectable"))
{
string inventoryType = other.gameObject.GetComponent<Collectable>().inventoryType;
print("We have collected a:"+ inventoryType);
inventory.Add(inventoryType);
print("Inventory length:" + inventory.Count);
Destroy(other.gameObject);
string wordType = other.gameObject.GetComponent<Collectable>().inventoryType;
}
}
I want instead of:
string[] characters = new string[] { "A", "B", "C", "D" };
the string to be from the gathered letters.
After that, to be generated a word from an existing list with words.
How do I do that?