我有一个列表和文字:
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
。
知道我该怎么做吗?
答案 0 :(得分: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()];