2016-11-25 57 views
0

我正在將代碼打印到TextMesh,並且它始終在變化。我需要將字符串保存到PlayerPref,以便我可以加載它。爲了使文本正確合適,我必須使用\n強制在字符串中換行。如何通過PlayerPref保持字符串換行符?

string text = "line1\nline2"; 

    PlayerPref.SetString("Text", text); 
    LocationSide1.GetComponent<TextMesh>().text = PlayerPrefs.GetString("Text"); 

如果我設置文本,而不PlayerPref它會做一個換行符:

line1 
    line2 

有了它打印作爲一個行PlayerPref

line1\nline2 

如何任何想法解決這個問題?

回答

2

似乎'\'已被轉義。

您是否嘗試過使用字符串?

using System.Text.RegularExpressions; 

[...] 

string text = "line1\nline2"; 

PlayerPref.SetString("Text", text); 
LocationSide1.GetComponent<TextMesh>().text = Regex.Unescape(PlayerPrefs.GetString("Text")); 
myString = Regex.Unescape(myString); 
+0

很棒的工作! –

相關問題