Comparing Two Arrays

  var score1 = 600;
  var score2 = 200;
  var score3 = 100;
  var score4 = 1000;
  var score5 = 50;

  var playerscore = [score1,score2,score3,score4,score5];
  var playername  = ["player1","player2","player3","player4","player5"];

   function OnGUI()
       {

     System.Array.Sort(playerscore,playername);

       }

Here i am trying to sort the score from highest to lowest.that is working fine.

here problem is when i sort the score and player name.the player is displaying wrong score.

let my player name and score be

       player1-100
       player2-500
       player3-200

after sorting it changes to

     player1-500
     player2-200
     player3-100

so i want after sorting the score also player name should display the correct score. when i sort the score from highest to lowest the name should rearrange as the players score.

so how can i compare the player name and score after sorting the score.so that the correct player occupies the correct score.player name should arrange according to the player score.

and i want to display the content in a gui.i tried many form but not able to solve this problem.

thanks in advance

1 Answer

1

It sounds like you need to use Javascript's arrays if you want to do any sort of robust sorting (see here).

I found a nice reference explaining how you can sort with multiple values here. Hope this helps.