PickupDemoGUI script

Options
Hi! I'm trying to do two lists including the members of a team. I just used the PickupDemoGUI script, which was relatively simple, but the main rule of unity "it can't be easy" hit me again. Without modifications the script works perfectly and shows all the members of each team, but when I change the way to display it: GUILayout.Label () replaced by TextMesh.text = (), there is only one member appearing on this textMesh. Is there a way to display the same thing that appears with the GUI? Thank you

Comments

  • Hi forplayers,

    using a TextMesh for displaying the team members works for me. Make sure that your string representation is correct. While testing I forgot to do a word wrap after each player. Having this mistake in game, made it look like only one team member appears on the list.
  • forplayers
    Options
    Thank you very much. Indeed, I didn't do a world wrap after each player. I did some tries but it is still not showing each player. I will continue to try. That would be nice if you explain to me it, through a piece of code. Anyway thank you for shown me the good way!
  • Hi forplayers,

    this is nothing special, I simply copy/pasted the existing code and did some adjustments, so that it matches the new conditions when using a TextMesh.

    TextMesh t = GameObject.Find("Text1").GetComponent<TextMesh>(); t.text = string.Empty;

    This is for getting a reference to the TextMesh. Please try to avoid Find(...) function calls because they are really slow. However the more important part is to clear the text component because we want to completely refill it using our values. Those two lines are placed before iterating through the teams. When inside the first foreach loop you need to add the team name to the text.

    t.text += "Team: " + teamName.ToString() + "\n";

    Lastly when inside the inner foreach loop (iterating through all players of the current team) you have to add the current player to the text.

    t.text += " " + player.ToStringFull() + " Score: " + player.GetScore() + "\n";
  • forplayers
    Options
    Thank you so much! It works perfectly after some modifications (text goes to infinity). In fact, my other script was the remains of the demo script and it became a real jumble. Thank you again