Search Unity

Change text colour if correct/wrong

Discussion in '2D' started by Newt42, Mar 19, 2018.

  1. Newt42

    Newt42

    Joined:
    Dec 1, 2017
    Posts:
    1
    Hi I am very new to unity
    At the moment I am trying to create a typing tutorial.
    So when the player types 'f' the color of the 'f' would change to green and the player would continue to type on.
    So I am trying to get the text to change color to 'green' if correct and 'red' if wrong.
    At the moment the letters on screen are just text.
    Was wondering if someone could point me in the right direction or start me off please.
    Thanks for your time
    1.PNG
     
  2. Varishaa

    Varishaa

    Joined:
    Feb 19, 2018
    Posts:
    16
    Well i can imagine a list of these characters for tracking. You track the current index of the list the next typed character ist checked against. So if the character is ok, you increase index, and handle the color change. If the typed character is wrong you can make the color red and think about to remain at the same index or go on. This is just about the check if the typed character was correct.
    For the color think i think the list will contain the gameobjects with the text component linked to it. So you can query it from within the class that handle the list.

    How do you create these characters? Their objects need to be added to the list, maybe dynamically.
     
  3. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    Either make a Text UI element for each letter, or one giant single one using rich text to color each letter one by one. Whatever is easier.
     
    JoeStrout likes this.