Unity UI How to make a chat box?

I have searched for how to do this on youtube, and google, but all I find is void OnGUI. Nothing for the new UI System. So I was wondering if anyone can help me figure this out.

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;
    using System.Collections.Generic;
    
    /// <summary>
    /// This script is attached to the MultiplayerManager, 
    /// and is the foundation for the multiplayer system.
    /// </summary>
    public class MultiplayerScript : MonoBehaviour {
    
        //Menu Header.
        public Text header;
        public Text displayID;
    
        private string connectToIP = "127.0.0.1";
        private int connectionPort = 26500;
        private bool useNAT = false;
        private string ipAddress;
        private string port;
        private int numberOfPlayers = 5;
    
        public string user_ID;
        public string serverName;
        public string serverNameForClient;
    
        //References....
        private GameObject ClickedButton;
    
        public GameObject sideBarObjects;
        public GameObject bodyObjects;
        
        public GameObject serverTypeObjects;
        public GameObject hostObjects;
        public GameObject connectObjects;
    
        public InputField IPField;
        public InputField PortField;
    
        public List<GameObject> Avatars;
        public GameObject myAvatar;
    
        public GameObject userConnectedObjects;
        public GameObject userHostedObjects;
        public GameObject lobbyObjects;
    
    
    //ChatPanel Variables----------------
        private GameObject messageAvatar;
        private string messageToSend;
        private Text inputField_Message;
        private string communication;
        private InputField chatInputField;
    
    //----------------ChatPanel Variables
    
    
        void Awake()
        {
            displayID.text = GameObject.Find("UserDataObject").GetComponent<UserData>().ID;
        }
        public void on_Button_Click(string buttonName)
        {
            //-----------------------------------------------------------------
            //If we are not connected to a server
            //Allow us to connect
            if (Network.peerType == NetworkPeerType.Disconnected)
            {
    
                ClickedButton = GameObject.Find(buttonName);
    
                switch (buttonName)
                {
    //SideBarButtons-----------------------------------------
                    case "Button_Play_Now":
                        break;
                        
                        //The Multiplayer Button
                    case "Button_Multiplayer":
                        header.gameObject.SetActive(true);
                        header.enabled = true;
                        header.text = "Server Type";
                        bodyObjects.SetActive(false);
                        serverTypeObjects.SetActive(true);
                        break;
            //-----------------------------------------------SideBarButtons
    
                    case "Button_Host_BackToHome":
                        serverTypeObjects.SetActive(false);
                        bodyObjects.SetActive(true);
                        header.enabled = false;
                        break;
    
    
    //ConnectToServerButtons----------------------------------
    
                        //The connectToServer Button
                    case "Button_Connect_To":
                        header.text = "Connect To Server";
                        serverTypeObjects.SetActive(false);
                        connectObjects.SetActive(true);
                        break;
    
                        //The connectToServer connect button.
                    case "Button_Connect_Connect":
                       //Connect to a server with the IP and Port specified by the user.
                            Network.Connect(connectToIP, connectionPort);
                            header.text = "Multiplayer Lobby";
                            connectObjects.SetActive(false);
                            lobbyObjects.SetActive(true);
                            userConnectedObjects.SetActive(true);
                            sideBarObjects.SetActive(false);
    
                        break;
                        //Disconect from server.
                    case "DisconnectButton":
                        Network.Disconnect();
                        //void OnPlayerDisconnected(NetworkPlayer netPlayer)
                        //{ //When the user leave the servers, delete them and there
                            //RPC's So others do not still see them.
                          //Network.RemoveRPCs(netPlayer);
                          //Network.DestroyPlayerObjects(netPlayer);
                       // }
                        break;
                        //The ConnectToServer Back Button.
                    case "Button_Connect_Back":
                        serverTypeObjects.SetActive(true);
                        header.text = "Server Type";
                        connectObjects.SetActive(false);
                        break;
            //------------------------------------------Connect To Server Buttons
                        
    //Host Server Buttons---------------------------------
                        //The HostAServer Button
                    case "Button_Host_Server":
                        header.text = "Host A Server";
                        serverTypeObjects.SetActive(false);
                        hostObjects.SetActive(true);
                        break;
    
                        //The initialize server button
                    case "Button_Host_Connect":
                        //Set the port to user input.
                        connectionPort = int.Parse(PortField.text);
                        connectToIP = IPField.text;
                        Network.InitializeServer(numberOfPlayers,
                            connectionPort, useNAT);
    
                        //Write details to console.
                        Debug.Log("Server Initialized." + "

" +
"Server IP: " + connectToIP + "
" +
"Server Port: " + connectionPort.ToString() + "
" +
"MaxPlayers: " + numberOfPlayers );

                        header.text = "Multiplayer Lobby";
                        hostObjects.SetActive(false);
                        userHostedObjects.SetActive(true);
                        lobbyObjects.SetActive(true);
                        sideBarObjects.SetActive(false);
                        //Get the ID of the user.
                        //user_ID = GameObject.Find("UserDataObject").GetComponent<UserData>().ID;
                        break;
    
                        //The ButtonHostBack Button.
                    case "Button_Host_Back":
                        serverTypeObjects.SetActive(true);
                        header.text = "Server Type";
                        hostObjects.SetActive(false);
                        break;
    
    //-------------------------------------------Host Server Buttons
    
    
    //Chat Box Functionality---------------------------------------
                    case "Button_Send":
                        messageToSend = "";
                        Text chatText = GameObject.Find("Text_Chat").GetComponent<Text>();
    
                        //The user's input.
                        string message = GameObject.Find("Text_UserInput").GetComponent<Text>().text;
    
                        break;
    //----------------------------------------ChatBox Functionality
    
    
    
                }
            }
        }
      
    }

Everything you need to make a chat system in the new GUI is there. Here’s a screen shot consisting of a Panel, a Text, an InputField, and a Scrollbar.

None of these things have any code to drive them and actually make them interact together, I’m just showing a basic setup.

If it’s the actual programming of the chat system you need help with, then again that’s still not one question someone can answer. You can just dive in and try it and come back with a new question if your get stuck on something!

You don’t necessarily need to instantiate a new text object with every input line, it might be enough to just append to the Text.text field and slap a new line character at the end. Though if you want avatars a la Facebook, yeah I suppose you’ll be instantiating a little prefab with a Text object and an Image object.

Text box example