I am making some localized tips to be displayed when my player enters an area.
These tips are displayed over the characters head.
I have a gameObject with an exposed string, so that I can place tips around my scene, and enter the message I want to have displayed. The string is then passed forward to a TextMesh when the character collides with the tip.
The problem I am encountering is entering new line (
) into the string in the inspector.
The escape character is shown in inspector but is left out in game ( the '\' is gone, but not the 'n').
I have tried entering
by using alt + enter ( as suggested in the reference manual ).
But it doesn't seem to work.
Has anyone managed to input newlines through the inspector? (how the hell did you do that :o?)
duck
2
This appears to be a bug in the windows version of Unity. You can't manually type a return character into an inspector text field, and
doesn't work.
The only workaround for this is to copy and paste a return character (for example, from notepad).
Not sure if this question is still alive, but I found another workaround to put a newline into a string in the inspector:
function Start () {
stringname = stringname.Replace("NEWLINE","
");
}
Just place NEWLINE in your string, or replace the NEWLINE in the script with something else.
Molix
3
You can also create a custom inspector that uses a TextArea, rather than a TextField, for the string in question.
Picked up Molix idea :
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(TextMesh))]
public class TextEditor : Editor {
public override void OnInspectorGUI () {
this.DrawDefaultInspector();
TextMesh current_target = target as TextMesh;
EditorGUILayout.LabelField(" Text:", "");
current_target.text = EditorGUILayout.TextArea( current_target.text,GUILayout.MaxHeight(500f));
}
}
In windows newline is "
" so → “hello
new line”
illu07
9
None of this helped me.
I have a string which i should assign through the inspector.
My solution is, that i added the [TextArea] attribute, now i can use my Enter key and everything works like expected.
nervu0
11
[Multiline] string whatYouWantToDisplay;
For adding new line just use ’
’ as character sequence only ’
’ now working at all.
Following example works perfectly in my game.
public static string helpText1 = "A palindrome is when something \
is the same forward and backward,
like mom, dad, race car. Arrange
the tiles so the pattern is a
palindrome by touching and
dragging tiles.";
muzboz
12
I found a good solution at this thread:
Add the TextAreaAttribute to your string variable, and the Inspector will now provide you with a larger text entry box that allows you to just use the Enter key to make carriage returns. Yay!
eg:
[TextArea]
public string myString;
Malcire
8
‘/n’ is working in Unity 5 for windows for me. You just need to set vertical to overflow instead of truncation and increase the text height enough.
new line character:
System.Environment.NewLine
for example:
string text = "this is single line" + System.Environment.NewLine + "this is another line";