0

I was making an word puzzle game just like book worm, i have 16 text UI element on my hierarchy and each of one has script on it that responsible for setting the value.

I tried to setting up manually the letters of the answers, like for example the answer is "sample" every char i put it on every text ui

    void Start()
{ 
    Assign = this.GetComponent<Text>();
    split = getAnswer().ToCharArray();
    if (Ans) {
        Assign.text = split[randAns()].ToString().ToUpper();
    }
    else if (isStatic) {
        Assign.text = Assign.text;
    }
    else {
        Assign.text = listLetters[randLetters()].ToUpper();
    }
}

My code is on manual, i have bool of "Ans" if its true the letters will be assign on the text ui will be get in the letter from the answer, if the "isStatic" is true letter will be set will come from random letters from a to z. My question is how can i make it dynamic it will automatically set the letters from answer without repeating each letter.

  • If you're taking a random value from a list of characters, simply remove the character you've chosen every time you choose and you never get the same letter again. – Fredrik Schön Jun 18 '19 at 17:09
  • how sir? when the script start running it will assign letters, i have 16 text ui with one same script which responsible for assigning their value – Mark Laurenz Jun 18 '19 at 17:15
  • Ideally you would want a single script for dictating which object will display what letter, you can start from there – Anton Mihaylov Jun 18 '19 at 19:07
  • I have only 1 script and i attached to 16 text ui, the problem is i cant check the repetition of letters come from the answer, so if the answer is "sample", i cant check if the letters from it is repeated – Mark Laurenz Jun 18 '19 at 19:24
  • Possible duplicate of [Random number generator with no duplicates](https://stackoverflow.com/questions/26931528/random-number-generator-with-no-duplicates) and also [Randomize a List](https://stackoverflow.com/q/273313/7111561) – derHugo Jun 19 '19 at 05:06

0 Answers0