- Home /
UI shows text not in order
Im making a fake chat for a visual novel/otome but the text on screen is not the same as in the script. Usually, the last "message" shows first and i don´t know why. The message instanciates every second, so the last message on the array should not be sent, but stills shows, even when in the debugger i cant yet see it. i really don´t know what am i doing wrong since in the debugger shows with the order i want. Thank you so much!
Heres the example and how it´s instanciated.
the chat story:
static string[] test = new string[]
{
"First Message:Kayro",
"Hola, sirve ya este chat?:Kosma",
"Holaaaaa:Kayro",
"Hey:Luan",
"Si llegan los mensajes:Luan",
"Cool:Luan",
"SIGNIFICA QUE YA SIRVEEEE:Kayro",
"WUUUU:Kayro",
"Pero si tu no hiciste nada dude:Luan",
"Last Message:Kosma",
"Choice"
};
how its sent to the manager:
IEnumerator sendChat()
{
while (true)
{
yield return new WaitForSeconds(1.0f);
if (test.Length > click)
{
//Debug.Log("Numero de clicks: " + click);
Say(test[click]);
clicks();
}
}
}
public void Say(string test)
{
string[] escena = test.Split(':');
string sp = escena[0];
string oc = (escena.Length >= 2) ? escena[1] : "";
manager.Historia(sp, oc, cho);
//Debug.Log(oc + " envia: " + sp);
}
the manager:
public void Historia(string di, string pj, string [] cho)
{
Img = SMS.transform.Find("User").gameObject;
MessageIcon = Img.transform.Find("Name").gameObject;
MessageText = Img.transform.Find("Text").gameObject;
Message = SMS.transform.Find("Mensaje").gameObject;
var parent = ChatContainer.transform;
var messageicon = Instantiate(SMS);
messageicon.name = "SMS " + click;
clicks();
messageicon.transform.SetParent(parent, false);
Message.GetComponentInChildren<Text>().text = di;
MessageIcon.GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/Characters/" + pj + "/Icon");
MessageText.GetComponentInChildren<Text>().text = pj.ToUpper();
}
Answer by Tomatotom1234 · Jan 07, 2021 at 05:22 PM
its because the first message is older than the newest messages so obviously the new ones will be in front
the "messages" iterate from top to bottom, so the last message should be at the bottom :c
Answer by unity_hL4PWxG3fblNGQ · Jan 07, 2021 at 09:57 PM
FORGET IT! I JUST SOLVED IT I WAS ASSIGNING WRONG THE MESSAGES
Your answer
![](https://koobas.hobune.stream/wayback/20220613022831im_/https://answers.unity.com/themes/thub/images/avi.jpg)