• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by unity_hL4PWxG3fblNGQ · Jan 07 at 04:04 PM · uiwaitforsecondsinstantiate prefab

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. alt text

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();
         }

uni1.png (83.7 kB)
uni2.png (15.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tomatotom1234 · Jan 07 at 05:22 PM

its because the first message is older than the newest messages so obviously the new ones will be in front

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unity_hL4PWxG3fblNGQ · Jan 07 at 09:13 PM 0
Share

the "messages" iterate from top to bottom, so the last message should be at the bottom :c

avatar image
0

Answer by unity_hL4PWxG3fblNGQ · Jan 07 at 09:57 PM

FORGET IT! I JUST SOLVED IT I WAS ASSIGNING WRONG THE MESSAGES

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

194 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

script runs fine on start up, but slows on second attempt 1 Answer

Canvas, instantiate and adjust size of image to fit parent 0 Answers

Custom Script and Controls for Canvas UI button ?? 1 Answer

Instanciate prefab responsively 1 Answer

Changing scenes with unity 4.6 UI 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges