i'm trying to print a string letter by letter for UI Text of Unity.
With each click of a button, the Stampa function, must print a letter. Up to this point everything is working perfectly.
But if I try to print a newline "\n" the function ignores him and continues to print on the same line.
This is my code:
using UnityEngine;
using UnityEngine.UI;
public class Click : MonoBehaviour {
public static Text txt;
public static int indice = 0;
public string asd = "String1 \nStriga2";
void Awake() {
txt = GameObject.Find("Cmd").GetComponentInChildren<Text>();
}
public void Clicked() {
Stampa(asd ,indice);
indice++;
}
void Stampa(string stringa, int i) {
txt.text += stringa[i];
}
}
That produces this result(unwanted):
I also tried to print the entire string at the same time (not a letter at a time) as follows:
txt.text = "String1 \nStriga2";
That produces this result(wanted):
How can I get this second result by printing letter by letter?
string[i]
is a slash, if it is then add bothi
andi+1
\$\endgroup\$