How to make a line break in a GUI Label

Hey guys,

I was wondering, is it possible to make a simple line break in a GUI Label?

Because I have a fairly long string that is being written to the screen, and I would rather it to be split to a second line rather than stretch across the whole screen…

Thanks

-Grady

In java, javascript, C, C++, C#, and similar languages, you need to use an escape character to display certain characters such as new line or have " show up inside a string literal.

They are called escape characters because they “escape” from their normal useage.

All escape characters start with a \ to tell the compiler that the next character should be interpreted differently than normal.

Here are some common ones:

  
	New line
  		Tab
  \v    Vertical Tab
  \b	Backspace
  \r	Carriage return
  \f	Formfeed
  \\	Backslash
  \'	Single quotation mark
  \"	Double quotation mark
  \d	Octal
  \xd	Hexadecimal
  \ud	Unicode character

or “line one” + Environment.NewLine + “line two”

If you are not getting what you want with
and want to avoid referencing to System.Environment you can use

e.g. MyText.text = "There will be a carriage return and newline at the end
";

There is another solution for this:
string a = “String you want to get from somewhere with
"
a.Replace(”
", "
");
This way Unity gets "
" as a line break. Not my solution but I can’t remember where I have seen it.

Then new line character is "
".

“line one
line two”

Thanks guys…
Now I don’t have to format my automatically written script.
It’s all done for me.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GetVerticesAndTriangles : MonoBehaviour
{
[SerializeField] private MeshFilter meshFilter;
[SerializeField] private Mesh mesh;
[SerializeField] private Vector3 vertices;
[SerializeField] private int triangles;
public string output;

private void Start()
{
    mesh = GetComponent<MeshFilter>().mesh;

    for (var i = 0; i < mesh.vertices.Length; i++)
    {
        //vertices<em>[0] = vertices_[0] * 2;_</em>

}
vertices = mesh.vertices;
triangles = mesh.triangles;
createOutput();
createOutput2();
updateTheMesh();
}
private void createOutput()
{
output += “using System.Collections;” + "
" + “using System.Collections.Generic;” + "
" + “using UnityEngine;” + "
" + "
";

output += "[RequireComponent(typeof(MeshFilter))] " + "
";

output += “public class MeshGenerator : MonoBehaviour” + "
" +“{” + "
";

output += " " + “Mesh mesh;” + "
" + " " + “Vector3[] vertices;” + "
" + " " + “int[] triangles;” + "
" + "
" + " " + “// Use this for initialization” + "
" + " " + “void Start()” + "
" + " " + “{” + "
" + " " + " " + “mesh = new Mesh();” + "
" + " " + " " + “GetComponent().mesh = mesh;” + "
" + " " + " " + “CreateShape();” + "
" + " " + " " + "UpdateMesh(); " + "
" + " " + “}” + "
";

output += " " + “void CreateShape()” + "
" + " " + “{” + "
";

output += " " + " " + “vertices = new Vector3[]” + "
" + " " + " " + “{”;

for (var i = 0; i < vertices.Length; i++)
{
output += "
" + " " + " " + " " + “new Vector3 (” + ((float)vertices[0]).ToString() + "f, " + ((float)vertices_[1]).ToString() + "f, " + ((float)vertices*[2]).ToString() + “f),”;
//Debug.Log(vertices[0]);
}
output += "
" + " " + " " + “};”;

}
private void createOutput2()
{
output += "
" + " " + " " + “triangles = new int[]” + "
" + " " + " " + “{”;

int lineSep = 0;
for (var i = 0; i < triangles.Length; i++)
{
if (lineSep == 0)
{
output += "
" + " " + " " + " ";

}
lineSep++;
if (lineSep > 2)
{
lineSep = 0;
}
output += triangles + ", ";
}
output += "
" + " " + " " + “};” + "
" + " "+ “}”;

}
private void updateTheMesh()
{
output += "
" + " " + “void UpdateMesh()” + "
" + " " + “{” + "
" + " " + " " + “mesh.Clear();” + "
" + " " + " " + “mesh.vertices = vertices;” + "
" + " " + " " + “mesh.triangles = triangles;” + "
" + " " + “}”;

output += "
" + “}”;

}*_

}

Ok, i’m trying to load text, stored in public string, to Text on UI.
How should i wrap this text then inputting it in this string from Inspector?
Just adding "
" or "
" doesn’t work for me. It’s just shows text as is.
If i copy text with “enters” from Notepad, it shows only text before first “enter”.