I know there have been a few threads on this already, but I just can’t make sense of the answers.
I’m making a command line interface game, and I want to have errors, like “command not recognised” appear in the output text box as red, while keeping the other text the default colour, here’s what I have:
switch (inputCommand)
{
case “MainEngineStart;”:
Debug.Log(“ROCKET HAS BEEN LAUNCHED”);
startTime = Time.time;
break;
default:
textOutput.text = (textOutput.text + “\t ERROR: Command not recognised”) + “\n”;
break;
}
can I really not just have something like “\t ERROR: Command not recognised”.ColourRed() ?
This is my first post, any help would be appreciated 
Thanks,
Fred T.A
pretty sure you can do something like
textOutput.color = new Color(1,0,0,1); // the r g b a values u want.
textOutput.text = (textOutput.text + "\t ERROR: Command not recognised") + "\n";
break;
it will set new rgb values before being called,
1 Like
Awesome thanks that now changed the colour 
This presents a new problem though, to add next to the textOutput text box I’m setting the text to what’s already in the text box, plus the new text that I want to output, this means that I’m effectively re-writing the whole text each time, is there anyway around this?
Uhh, I can’t quite make out what you mean…
Do you already have something in the text box and simply want to add “\t ERROR: Command not recognised” to the end of it?
Yeah, exactly, so I keep the old lines of text in the box, and add a new line underneath it
Will there be more text to be added to the same textfield in inspector? or just them two lines, if not you can do.
private string currenttext; // the current text in the textbox,
void Start()
{
currenttext = textOutput.text; // store in here
}
// then when you want to add it to the new one
textOutput.color = new Color(1,0,0,1);
textOutput.text = oldtext + "\n" + ERROR: Command not recognised" + "\n";
This should display what you want, but will change all the text to red, if you don’t want this I can further assist 
I’ve attached a picture of what I mean, so yeah I will need more text in the field, what I’m aiming for is to use the colours black for default text, and green, red and yellow for other text.
In the image, the error messages would be in red
Ah okay so a good way for this is specifying all the text you want to output in an array of strings in script.
public string[] textstuff = new string[6] /
void Start()
{
// using the hash codes for different values (you can get these from the RGB picker in inspector red = E10707D0
textstuff[0] = <color=#E10707D0> stuff typed in red</color>
textstuff[1] = <color=#E10707D0> stuff typed in orange</color>
StartCoroutine(swaptext());
}
then run this all in a coroutine
IEnumerator swaptext()
{
bool start = false;
string temptext = " ";
for (int i = 0; i < textstuff.length; i++)
{
while (!start)
{
{
temptext+= string.Format("{0}\n", textstuff[i]);
yield return null;
}
textOutput.text = tempString;
}
}
}
}
try this out, see if it displays all the different colors you want in the textfield (without input) then if so, you can start adding input so (i) increments by 1 to display new lines.
Thanks for the help, I’ll give it a go 
I also just found out that changing the colour of the text changes the colour of all text in the box, not just text that is output after the colour is changed…
so if I had
output “1”
output “2”
change to red
output “3”
we wouldn’t get black numbers 1 and 2 and a red 3, we would get black 1 and 2, which would then turn red, with a red 3 added on
…that’s a problem right?
Hmm, try my method, if it’s a problem ill try figure a way around this! 
Given this a good go but can’t make it compile, the problem seems to be with the line
textstuff[0]=<color=#E10707D0>
It doesn’t want to assign a colour to a string, throwing “color does not exist in the current context” errors, etc
If you run this
public class TextScript : MonoBehaviour {
public string[] textstuff = new string[6];
public Text textthing;
string tempstring = " ";
void Start()
{
textstuff[0] = "<color=#E10707D0> stuff typed in red</color>";
textstuff[1] = "<color=#FF911CFF> stuff typed in orange</color>";
textstuff[2] = "<color=#E10707D0> stuff typed in red</color>";
textstuff[3] = "<color=#FF911CFF> stuff typed in orange</color>";
textstuff[4] = "<color=#E10707D0> stuff typed in red</color>";
textstuff[5] = "<color=#FF911CFF> stuff typed in orange</color>";
for (int i = 0; i < textstuff.Length; i++)
{
tempstring += string.Format("{0}\n", textstuff[i]);
}
textthing.text = tempstring;
}
}
It will provide different colors, did you remember to do speechmarks for the strings?
The next step is to do an iteration where i increases on certain events to add the next line, what i provided just does it all on start 
1 Like
Ah brilliant that works perfectly! Thanks a lot, been banging my head against this for ages (first Unity project)
This lets me output certain lines different colours, while not changing the colour of the other text, perfect
Thanks again!
Welcome! goodluck with your first project 