c# - 如何打印列表中游戏对象的位置?

标签 c# unity3d

我有一个列表和文本:

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/

相关文章:

c# - 从控制台获取 C# 输入但不返回正确的输出

c# - 我如何优化这个像素不透明度计算?

c# - 如何检查表中是否存在值,如果存在则删除它?

c# - 当另一个 float 上升时,一个 float 的值减少

c# - Unity 180 旋转 Texture2D,或者翻转两者

unity3d - 视场棕褐色

c# - 如何重写数据集中表上的 TableAdapter 方法?

c# - 如何使用 C# 从移动设备读取序列号?

c# - Unity粒子系统: Change Emitter Velocity with Script

c# - transform.localPosition 与 trans.localPosition(缓存)