- Home /
This question was
closed Feb 12, 2017 at 06:56 AM by
StarlingSoftworksInteractive.
Question by
StarlingSoftworksInteractive · Feb 08, 2017 at 04:06 PM ·
c#buttonscript.unity5scripting beginner
How to keep the old line text?
I have been trying to figure out this but with no success . What I am trying to do is to keep the old text while the script adds the new text below the old text.
public GameObject Text_Object;
private Text textComponent;
void Start () {
//gets the text UI Object in canvas component
textComponent = Text_Object.GetComponent<Text>();
textComponent.text = "Hello";
Text2();
}
void Text2(){
textComponent.text = "Hey";
}
Basically as you can see the first text gets replace with the second text. What I'm trying to do keep the old text while if I press T it prints the new text below the old text and also add a command when they hit D it clears the text new and old text.
Comment
Best Answer
Answer by herDev · Feb 08, 2017 at 07:12 PM
Hi, you just need to make a minor change:
void Text2()
{
textComponent.text += "\n" + "Hey";
}
This basically makes it additive: textComponent.text = textComponent.text + "\n" + "Hey"; "\n" writes to a new line.
Just make sure that your text element height is high enough for multi-line text or you won't see the second line.
Hope that helps!