1

我有一个列表和文本:

List<GameObject> EnteredPlayers = new List<GameObject>();
public Text finishText;

当玩家进入触发器时,他们将被添加到列表中:

if (col.gameObject.tag == "finish") {

        EnteredPlayers.Add(player);
        finishText.text = //player's position in list here
    }

我想打印玩家在列表中的位置。例如,如果他们的位置是 [0],那么文本会说1st place.

知道我该怎么做吗?

4

1 回答 1

3
// Add the player
EnteredPlayers.Add(player);

// Get the position
int position = EnteredPlayer.Count

// Create a dictionary with the position names
// Put this dictionary outside of your method managing the games
Dictionary<string, string> positionNames = new Dictionary<string, string>(){
    { "1", "First" },
    { "2", "Second" },
    { "3", "Third" }
};

// Assign the label text
finishText.Text = positionNames[position.ToString()]; 
于 2015-10-17T00:14:54.247 回答