Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

charArray elements to each UI Text of letter objects

Discussion in 'Scripting' started by freedom667, Jan 26, 2018.

  1. freedom667

    freedom667

    Joined:
    Sep 6, 2015
    Posts:
    424
    I have letter objects and each object has UI Text. The objects increase according string's length (like at picture). Also the string converting to char array as random. So I want to put elements in char array to each UI Text of letters object as seperatly.



    For Example: string is "answer". Sure, char array will be ("a","n","s","w","e","r"). So Letter(0).GetChild(0).text will be "a", Letter(1).GetChild(0).text will be "n", Letter(2).GetChild(0).text will be "n" and it will go like this.

    How can i do this? I hope I could to tell you in an understandable way.

    Thanks
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Not sure what the question is. :)
    Are you asking how to get : 'a', 'n', 's' etc from the string? or something else?
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    @methos5k He wants to populate the text object on each Letter object. So that each box has a letter in it. From the looks of it, it's a tap the letter to create a word type game. I was going to put something, just hadn't had a chance.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ya, I knew the part about getting the letter. Do you want the letter you click to be the next one in the index?
    I feel like I half understand the question, sorry.
     
  5. freedom667

    freedom667

    Joined:
    Sep 6, 2015
    Posts:
    424
    I did convert the string to char array. I want to put the char array elements to UI Text of GameObjects (named "Letter(Clone)"). I explain in detail already or my english too bad. Also are you old? I've seen you at my before question. you answered it and you was seem teen
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    My age is posted in my profile :) Not sure how you thought I was young; young looking? talk like I'm young? :) lol

    So, you want to assign the character to text, like: "whatever.text = yourChar.ToString();"
    You could also just do:
    Code (csharp):
    1.  
    2. for(int i= 0 ; i < mystring.Length; ++i) whatever[i].text = mystring[i];
    Sorry I couldn't quite grasp the question.
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Perhaps when @Brathnann has time he can answer, as he might have a better intuition about your question. :)

    ** If my answer wasn't helpful, that is.
     
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Pretty much the code you showed was similar to what I was thinking.
     
  9. freedom667

    freedom667

    Joined:
    Sep 6, 2015
    Posts:
    424
    Thanks a lot. I made it through your idea. :)
    Code (CSharp):
    1. for (int i = 0; i < letterArray.Length; i++) {
    2.             letters [i].GetComponentInChildren<Text> ().text = letterArray [i].ToString().ToUpper();
    3.         }
     
  10. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Cool, glad you got it sorted out. :)