- Home /
Question by
x20X-Studios834 · Apr 02, 2018 at 01:42 AM ·
unity 5uitext
"/n" not working
Hello, I've been following the unity 'Text Based Adventure Game' tutorial, but have run into a problem. /n does not create a new line. it simply shows up in my text, like so, "lorem ipsum /n" I am pasting the entire script because I am not sure where this problem originates from. Any help is greatly appreciated
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class gameController : MonoBehaviour
{
[HideInInspector] public roomNav roomNavigation;
List<string> actionLog = new List<string>();
public Text displayText;
void Awake()
{
roomNavigation = GetComponent<roomNav>();
}
void Start()
{
DisplayRoomText();
DisplayLoggedText();
}
public void DisplayLoggedText()
{
string logAsText = string.Join("/n", actionLog.ToArray());
displayText.text = logAsText;
}
public void DisplayRoomText()
{
string combinedText = roomNavigation.currentRoom.description + "/n";
LogStringWithReturn(combinedText);
}
public void LogStringWithReturn(string stringToAdd)
{
actionLog.Add(stringToAdd + "/n");
}
}
Comment
your backslash is wrong like @Bunny83 says. also sometimes if "\n" doesnt work for you. you can try "\r\n".
Best Answer
Answer by Bunny83 · Apr 02, 2018 at 02:02 AM
The escape character is the backslash "\", not the slash "/"
Answer by augivision · Apr 02, 2018 at 02:06 AM
Try
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class gameController : MonoBehaviour
{
[HideInInspector] public roomNav roomNavigation;
List<string> actionLog = new List<string>();
public Text displayText;
void Awake()
{
roomNavigation = GetComponent<roomNav>();
}
void Start()
{
DisplayRoomText();
DisplayLoggedText();
}
public void DisplayLoggedText()
{
string logAsText = string.Join("\n", actionLog.ToArray());
displayText.text = logAsText;
}
public void DisplayRoomText()
{
string combinedText = roomNavigation.currentRoom.description + "\n";
LogStringWithReturn(combinedText);
}
public void LogStringWithReturn(string stringToAdd)
{
actionLog.Add(stringToAdd + "\n");
}
}
"\n" is the correct way.