Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Chat History

Discussion in 'Scripting' started by hublard, Feb 20, 2018.

  1. hublard

    hublard

    Joined:
    Aug 19, 2015
    Posts:
    79
    Hello there,

    i have a question, and i think there is a easy solution but im not able to figure it out.

    to my problem:

    i got chat history. it should work like in every chat or game.

    a player can write something and text appear in history. when an other message comes it should appear under the other one and so on.

    but my problem is that the new message appears over the old one.

    here is my code:

    public void ChatHistoryUpdate()
    {
    if(ConstantFile.ChatArr.Count > 10)
    {
    int TempChecker = ConstantFile.ChatArr.Count - 10;
    for(int i=0; i<TempChecker; i++)
    {
    ConstantFile.ChatArr.RemoveAt (0);
    }
    }
    TXT_chathistory.text = "";
    for(int i=ConstantFile.ChatArr.Count; i>=0; i--)
    {
    TXT_chathistory.text += ConstantFile.ChatArr[i+1]+"\n";
    }
    }


    what do i have to change that new message appears as last one and the first message (top) will destroy.
     
  2. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    Did you try

    Code (CSharp):
    1. for(int i=0; i < ConstantFile.ChatArr.Count; i++)
    2.     {
    3.         TXT_chathistory.text += ConstantFile.ChatArr[i]+"\n";
    4.     }
     
  3. hublard

    hublard

    Joined:
    Aug 19, 2015
    Posts:
    79
    cool it works,

    thank you very much
     
  4. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    no problem.