Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scoreboard to GUI.Label problem

Discussion in 'Scripting' started by koodari1337, Jul 21, 2014.

  1. koodari1337

    koodari1337

    Joined:
    Jun 10, 2014
    Posts:
    4
    I am trying to get Scoreboard info to the GUI.Label but....

    Code im using

    1. privatevarPlayer_Name:String="";
    2. privatevarScoreboard:String="";
    3. privatevarPlayers:int=0;
    4. functionStart()
    5. {
    6. show_highscore();
    7. }
    8. function show_highscore()
    9. {
    10. var form =newWWWForm();
    11. form.AddField("action","show_highscore");
    12. var url ="http://localhost/score.php";
    13. var w = WWW(url,form);
    14. yield w;
    15. var received_data =Regex.Split(w.text,"</next>");
    16. var scores =(received_data.Length-1)/3;

    17. for(var i =0; i < scores; i++)
    18. {
    19. Players= scores;
    20. Player_Name= received_data[3*i];
    21. print("Name: "+ received_data[3*i]);
    22. }
    23. }

    24. functionOnGUI()
    25. {
    26. for(var i =0; i <Players; i++)
    27. {
    28. //Name
    29. GUI.Label(Rect(Screen.width/2-100,230+20*i,100,30),"Name: "+Player_Name);
    30. }
    31. }


    But the problem is that only print works... so

    Print gives Name: Player_1 Name: Player_2

    What is right

    but GUI.Label gives Name: Player_1 Name: Player_1

    This is the problem... i want it to show all players like print function does but i cant add GUI.Label in show_highscores function so what should i do??!!
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Ofcourse it gives 1 name only. You are setting only one name. That and use code tags.
     
  3. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    1. Code (csharp):
      1.  
      2. private var Player1_Name : String= "";
      3. private var Player2_Name : String= "";
      4.  
    Or
    Code (csharp):
    1.  
    2. var Player_Name : String[]; //set it to 2 in the inspector
    3.  
    4.  
    5.  
    6. for(var i =0; i < scores; i++)
    7. {
    8. Players= scores;
    9. Player_Name[i]= received_data[3*i];
    10. print("Name: "+ received_data[3*i]);
    11. }
    12.  
    13.  
     
    koodari1337 likes this.
  4. koodari1337

    koodari1337

    Joined:
    Jun 10, 2014
    Posts:
    4
    Yes it works! Thank you so much! :)