Pretty much the title, I’ve been learning basic Unity and C# through the “Creating A Text Based Adventure Game” tutorial, and now I’m improving it and making it my own.
I would like to change the displayed text so that the text the player inputs (for example “head towards the river”) is displayed in one colour, and the text displayed by the game (for example “you head towards the river…”) is displayed in another, so the player doesn’t get lost in all white (or any other colour) text displayed by both game text and input text.
I’d appreciate any help and please be gentle, I know that for some this is extremely obvious, but if it wasn’t obvious already, I’ve only recently started with programming/Unity.
Need more info. Tell me how you have it setup. Is it simply an inputfield that the player types into and then you transfer the text to another text box?
I’ll add this if it helps. By default, Unity’s text supports the color tag Redirecting to latest version of com.unity.ugui
which allows you to surround text to change it’s color. So if a player types text in, you can surround it with color tags when you display it.
There is also an asset called TextMeshPro on the asset store which is now free and if you’re doing a text based game, you might consider it as it’s designed to give you a lot of features for text handling.
Sorry for the late response, Yeah its pretty basic right now, a text appears and when you’re ready you input your action, submit it and the game responds to it, The text is typed through the InputField, and then showed on the DisplayText area
Here is my code for the text input:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextInput : MonoBehaviour
{
public InputField inputField;
GameController controller;
void Awake()
{
controller = GetComponent<GameController> ();
inputField.onEndEdit.AddListener (AcceptStringInput);
}
void AcceptStringInput(string userInput)
{
userInput = userInput.ToLower ();
controller.LogStringWithReturn (userInput);
char[] delimiterCharacters = { ' ' };
string[] seperatedInputWords = userInput.Split(delimiterCharacters);
for (int i = 0; i < controller.inputActions.Length; i++)
{
InputAction inputAction = controller.inputActions [i];
if (inputAction.keyWord == seperatedInputWords [0])
{
inputAction.RespondToInput (controller, seperatedInputWords);
}
}
InputComplete ();
}
void InputComplete()
{
controller.DisplayLoggedText ();
inputField.ActivateInputField ();
inputField.text = null;
}
}
and this is my code for Displaying the text
public void DisplayLoggedText()
{
string logAsText = string.Join("\n", actionLog.ToArray ());
displayText.text = logAsText;
}
public void DisplayRoomText()
{
ClearCollectionsForNewRoom ();
UnpackRoom ();
string joinedInteractionDescriptions = string.Join("\n", interactionDescriptionsInRoom.ToArray ());
string combinedText = roomNavigation.currentRoom.description + "\n" + joinedInteractionDescriptions;
LogStringWithReturn (combinedText);
}
and here is the screenshot of the Input field settings in a picture form
I hope it helped
So, if logAsText is your text you’re displaying and you want to change it’s colors, like I said, just add the color tags.
displayText.text = "<color=#00ffffff>" + logAsText + "</color>";
Just set the hex color to whatever you want. You can even tie it to a variable and set different colors if you want. You can also attach color tags to individual words.
If you use that TextMeshPro asset you can also insert small sprites, change the text font, and a lot more if you want to really spruce on the presentation.
Okay that worked, thank you so much for putting aside a bit of time for helping me! 
1 Like
No problem! Glad it’s working for you.