我有一个列表和文本:
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
。
知道我该怎么做吗?
最佳答案
// 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()];
关于c# - 如何打印列表中游戏对象的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33181203/