- Home /
Line break UI Text field
Hi I'm trying to set the text with string can't get the line break to work. want it to look this one but it looks like this all mess up
the code that i am use to set the items description
[SerializeField]
private Text description;
[SerializeField]
private string text;
public void OnMouseOver()
{
Debug.Log("isset");
description.text = text;
}
Answer by FM-Productions · May 02, 2017 at 06:52 PM
Hi,
you may find your answer here: http://answers.unity3d.com/questions/138464/how-to-make-a-line-break-in-a-gui-label.html
One short solution: use the character "\n" - without the double quotes - in your text variable for a line break.
What @Eicher means to say is that in C#, when we want to create a string with a line break, we use "\n" for this. This can be very useful, and if you find you need to do it often, you could always do something like this.
public string AddLine(string oldString, string newLine)
{
oldString += "\n" + newLine;
return oldString;
}
Now if you want to do this in the editor, and ensure that it comes out as a proper multi-lined string. You can choose a specific character like our codes line ending ";" and use it as a breaker. So in-Editor you can write it our like this.
This item is an item;
It does item-like stuff;
or
This is another item;It is very itemlike;
Then you can do this.
public void On$$anonymous$$ouseOver()
{
text.Replace(";", "\n");
description.text = text;
}
yes have tried but it is not working
where I'm trying to set the item description of all item and yes all of them have the script on them. so i can change it by what item it is
Your answer
Follow this Question
Related Questions
How to use special symbols 1 Answer
,InputField backspace returns already send text 0 Answers
What's your equivalent of old GUIStyle ? 0 Answers
How to measure the width of a string? 0 Answers