private void Client_MessageReceived(object sender, MessageReceivedEventArgs e) { //Verify the type of message is as we're expecting if (e.Message is SimpleMessage) { //Then cast it SimpleMessage msg = (SimpleMessage)e.Message; //Now we need to create a new UI object to put the message in so instantiate our prefab and add it //as a child to the chat window GameObject messageObj = Instantiate(messagePrefab) as GameObject; messageObj.transform.SetParent(chatWindow); //We need the Text component so search for it Text text = messageObj.GetComponentInChildren <Text>(); //If the Text component is present then get the DarkRiftReader from the message and read the text //from it into the Text component if (text != null) { text.text = msg.GetReader().ReadString(); } else { Debug.LogError("Message object does not contain a Text component!"); } if (scrollRect != null) { Canvas.ForceUpdateCanvases(); scrollRect.verticalNormalizedPosition = 0f; } } }