[英]How to print the position of a gameObject in a list?
我有一個列表和文字:
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()];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.