コード例 #1
0
    public void CreatePlayerHuds(List <Player> players)
    {
        int playerNum = 0;

        foreach (Player player in players)
        {
            GameObject newPlayerHudObj = Instantiate(PlayerHudPrefab);

            RectTransform newPlayerRect = newPlayerHudObj.GetComponent <RectTransform>();
            newPlayerHudObj.transform.SetParent(HudCanvas.transform);
            newPlayerRect.pivot            = _pivotAnchorPosition;
            newPlayerRect.anchorMin        = _pivotAnchorPosition;
            newPlayerRect.anchorMax        = _pivotAnchorPosition;
            newPlayerRect.anchoredPosition = _hudPosition;

            PlayerHud newPlayerHud = newPlayerHudObj.GetComponent <PlayerHud>();
            newPlayerHud.AssignPlayerToHud(player);
            _playerHuds.Add(newPlayerHud);
            newPlayerHud.playerHud = newPlayerHudObj;
            ++playerNum;

            // Hide the new HUDs
            newPlayerHudObj.SetActive(false);
        }
    }