static int AddPlayerMade(GameObject obj, byte[] data, int fromWho)
 {
     if (obj)
     {
         // Must be alive
         byte placePlayerMadeType = data [0];
         PlacePlayerMade.AddObject(obj.GetComponent <PlayerMove>(), OperationNetwork.getVector3(data, 1), OperationNetwork.getQuaternion(data, 13), placePlayerMadeType, obj.GetComponent <Combat>().team, (short)fromWho);
     }
     return(29);
 }
    void updateHud()
    {
        for (int i = 0; i < UnlocksEquipped.Length; i++)
        {
            if (UnlocksEquipped [i] != null && UnlocksEquipped[i].getHudType() == "Cooldown" && UnlocksEquipped[i].hudElement != null)
            {
                UnlocksEquipped [i].setCharge();
            }
            if (UnlocksEquipped [i] is TakeHealthWeapon && GetComponent <PlayerMove>().hudElement != null)
            {
                // Render "Health Taken"
                TakeHealthWeapon thw = (TakeHealthWeapon)UnlocksEquipped [i];
                if (thw.healthTaken >= TakeHealthWeapon.healthTakenReq)
                {
                    // Can use "ultimate" / "ubercharge"
                    GetComponent <PlayerMove>().hudElement.GetComponent <Text>().color = Color.green;
                    GetComponent <PlayerMove>().hudElement.GetComponent <Text>().text  = "(" + OptionsMenu.getBindString(OptionsMenu.binds[OptionsMenu.ULTIMATE_ABILITY]) + ") Health Taken: " + Mathf.FloorToInt(thw.healthTaken);
                }
                else
                {
                    GetComponent <PlayerMove>().hudElement.GetComponent <Text>().color = Color.yellow;
                    GetComponent <PlayerMove>().hudElement.GetComponent <Text>().text  = "Health Taken: " + Mathf.FloorToInt(thw.healthTaken);
                }
            }
        }
        // Phase shift (isn't an unlock) OR speed bost (isn't an unlock)
        if ((classNum == 0 || classNum == 3) && GetComponent <PlayerMove>().hudElement != null)
        {
            GetComponent <PlayerMove>().setCharge(classNum);

            if (GetComponent <PlayerMove> ().hudElement2 != null)
            {
                GetComponent <PlayerMove> ().hudElement2.transform.Find("Armor").GetComponent <Text> ().text = "Armor" + " (" + OptionsMenu.getBindString(OptionsMenu.binds[OptionsMenu.MAIN_ABILITY]) + ")";
                PlacePlayerMade.setCharge(GetComponent <PlayerMove> ().hudElement2, GetComponent <PlayerMove> ().isArmorOn, 1f);
                if (GetComponent <PlayerMove> ().isArmorOn == 0)
                {
                    GetComponent <PlayerMove> ().hudElement2.GetComponent <Image> ().color = new Color(0f, 0.7f, 0f);
                }
                else
                {
                    GetComponent <PlayerMove> ().hudElement2.GetComponent <Image> ().color = new Color(133f / 255f, 133f / 255f, 133f / 255f);
                }
            }
        }
    }
    void HudUpdate()
    {
        GameManager.UpdateKillFeed();

        HealthBarUpdate();

        UpdateTrapSelectionZoneMenu();

        for (int i = 0; i < trapsHud.Length; i++)
        {
            trapsHud [i].SetActive(isTrapSelectionMenuOpen);
        }

        respawnHud.transform.parent.gameObject.SetActive(Player.thisPlayer != null && Player.thisPlayer.playerObject == null);
        if (Player.thisPlayer != null && Player.thisPlayer.playerObject == null)
        {
            respawnHud.fillAmount = Mathf.Clamp01(1 - Player.thisPlayer.getRespawnTimer() / Player.thisPlayer.getNetRespawnTimer());
            respawnHud.transform.parent.GetComponent <Image>().fillAmount = Mathf.Clamp01(Player.thisPlayer.getRespawnTimer() / Player.thisPlayer.getNetRespawnTimer());
            int respawnTimer = (int)(Player.thisPlayer.getRespawnTimer() + 1);
            if (respawnTimer == 1)
            {
                respawnHud.transform.parent.Find("Text").GetComponent <Text> ().text = "Respawning in 1 second.";
            }
            else
            {
                respawnHud.transform.parent.Find("Text").GetComponent <Text> ().text = "Respawning in " + respawnTimer + " seconds.";
            }
        }

        // Class Selection Hud gets priority
        if (Player.thisPlayer && Player.thisPlayer.team == 1 && !OptionsMenu.classSelectionMenuOpen)
        {
            bool needTrap = false;
            for (int i = 0; i < Player.thisPlayer.trapTypes.Length; i++)
            {
                if (Player.thisPlayer.trapTypes [i] == 255)
                {
                    needTrap = true;
                }
            }
            if (needTrap && !PlayerHud.isTrapSelectionMenuOpen)
            {
                PlayerHud.isTrapSelectionMenuOpen = true;

                OptionsMenu.ChangeLockState();
            }
            else if (!needTrap && PlayerHud.isTrapSelectionMenuOpen)
            {
                PlayerHud.isTrapSelectionMenuOpen = false;
                OptionsMenu.ChangeLockState();
            }
        }

        if (Player.thisPlayer && PlayerHud.isTrapSelectionMenuOpen)
        {
            for (int x = 0; x < trapsChoices.GetLength(0); x++)
            {
                for (int y = 0; y < trapsChoices.GetLength(1); y++)
                {
                    trapsChoices [x, y].transform.Find("Text").GetComponent <Text> ().text = BuyNewTrap.trapNames [BuyNewTrap.trapIndecies[Player.thisPlayer.myRandomTrapChoices[x * trapsChoices.GetLength(1) + y]]];
                    trapsChoices [x, y].GetComponent <BuyNewTrap> ().buyId = Player.thisPlayer.myRandomTrapChoices [x * trapsChoices.GetLength(1) + y];
                    trapsChoices [x, y].GetComponent <BuyNewTrap> ().rowID = (byte)x;
                }
            }
        }

        // This is how HUD should work for all unlocks:
        if (Player.thisPlayer)
        {
            for (int i = 0; i < displayTraps.Length; i++)
            {
                byte actual = Player.thisPlayer.trapTypes [i];
                if (Player.thisPlayer.team != 1)
                {
                    actual = 255;
                }
                if (displayTraps [i] != actual)
                {
                    displayTraps [i] = actual;
                    if (displayTraps [i] == 255 || Player.thisPlayer.team != 1)
                    {
                        trapPlayerHudTypes [i].SetActive(false);
                    }
                    else
                    {
                        trapPlayerHudTypes [i].SetActive(true);
                        trapPlayerHudTypes [i].transform.Find("Text").GetComponent <Text> ().text = "(" + OptionsMenu.getBindString(OptionsMenu.binds [OptionsMenu.TRAP_1 + i]) + ") " + BuyNewTrap.trapNames [BuyNewTrap.trapIndecies[displayTraps [i]]];
                    }
                }


                if (displayTraps[i] != 255 && Player.thisPlayer.playerObject)
                {
                    int trapTypeIndex = BuyNewTrap.trapIndecies[Player.thisPlayer.trapTypes [i]];
                    PlacePlayerMade.setCharge(trapPlayerHudTypes [i],
                                              Mathf.Clamp01((Player.thisPlayer.playerObject.GetComponent <SyncPlayer>().playerTime - Player.thisPlayer.trapCoolDownsStartedAt [i]) / (float)(BuyNewTrap.baseTrapCosts [trapTypeIndex] * BuyNewTrap.maxTrapsLoaded[trapTypeIndex] * Time.fixedDeltaTime)),
                                              1f / BuyNewTrap.maxTrapsLoaded[trapTypeIndex]);
                }
            }
        }

        if (OperationNetwork.connected)
        {
            if (Time.time - lastNetworkSettingsRead > 1)
            {
                if (OperationNetwork.isServer)
                {
                    dataSentPerSecond = OperationNetwork.getClient(32767).dataSent / (Time.time - lastNetworkSettingsRead);
                    OperationNetwork.getClient(32767).dataSent  = 0;
                    networkSettings.GetComponent <Text> ().text = (int)(dataSentPerSecond / 100) / 10.0f + " KB/s";
                }
                else
                {
                    dataSentPerSecond            = RunGame.myClient.dataOutRate / (Time.time - lastNetworkSettingsRead);
                    RunGame.myClient.dataOutRate = 0;
                    float dataRecievedPerSecond = RunGame.myClient.dataInRate / (Time.time - lastNetworkSettingsRead);
                    RunGame.myClient.dataInRate = 0;

                    networkSettings.GetComponent <Text> ().text = "Sent: " + (int)(dataSentPerSecond / 100) / 10.0f +
                                                                  " KB/s Recieved: " + (int)(dataRecievedPerSecond / 100) / 10.0f + " KB/s";
                }
                lastNetworkSettingsRead = Time.time;
            }
        }

        if (OperationNetwork.connected && Player.thisPlayer != null && Player.thisPlayer.playerObject != null)
        {
            PlayerMove pMove        = Player.thisPlayer.playerObject.GetComponent <PlayerMove> ();
            float      touchPercent = DamageCircle.isTouchingDamageCircle(pMove.timeSinceTouchingDamageCircle);
            if (touchPercent > 0)
            {
                buffHud.transform.parent.GetComponent <Image> ().enabled = true;
                buffHud.enabled    = true;
                buffHud.fillAmount = touchPercent;
            }
            else
            {
                // Disable the rendering of it:
                buffHud.transform.parent.GetComponent <Image> ().enabled = false;
                buffHud.enabled = false;
            }
            healthHud.enabled = true;
            healthHud.transform.parent.GetComponent <Image> ().enabled = true;
            healthHudText.enabled = true;
            healthHud.transform.parent.GetComponent <Image> ().fillAmount = 1 - pMove.GetComponent <Combat> ().health / pMove.GetComponent <Combat> ().maxHealth;
            healthHud.fillAmount = pMove.GetComponent <Combat> ().health / pMove.GetComponent <Combat> ().maxHealth;
            healthHudText.text   = (short)pMove.GetComponent <Combat> ().health + " HP";

            if (Player.thisPlayer.playerObject != playerObjectHudLoaded)
            {
                playerObjectHudLoaded = Player.thisPlayer.playerObject;

                float origNum = getHudHeightUsed(classHud.transform);

                // Unload old hud:
                foreach (Transform t in classHud.transform)
                {
                    if (t.name != "AdjacentClassHud")
                    {
                        Destroy(t.gameObject);
                    }
                }
                foreach (Transform t in classHud.transform.Find("AdjacentClassHud"))
                {
                    Destroy(t.gameObject);
                }

                // Create new hud:
                foreach (Unlock unlock in Player.thisPlayer.playerObject.GetComponent <ClassControl>().getUnlocks())
                {
                    if (unlock != null)
                    {
                        unlock.setHudElement(classHud.transform, origNum);
                    }
                }

                int classLoaded = Player.thisPlayer.playerObject.GetComponent <ClassControl> ().classNum;

                // Phase through & Speed Boost are not unlocks, despite having some similar qualities: (Like the HUD)
                if (classLoaded == 0)
                {
                    Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement  = Unlock.setHudElement(classHud.transform, "Cooldown", "Phase Shift", OptionsMenu.MOVEMENT_ABILITY_BIND, null, origNum);
                    Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement2 = Unlock.setHudElement(classHud.transform, "Armor", "Armor", OptionsMenu.MAIN_ABILITY, null, origNum);
                }
                else if (classLoaded == 3)
                {
                    Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Cooldown", "Speed Boost", OptionsMenu.MOVEMENT_ABILITY_BIND, null, origNum);
                }
                else if (classLoaded == 4)
                {
                    if (OptionsMenu.hudPanels.ContainsKey("Healthtaken"))
                    {
                        Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Healthtaken", "Health Taken", OptionsMenu.ULTIMATE_ABILITY, null, origNum);
                    }
                }

                // The updating for the HUD is handled within the unlocks / class itself
            }
        }
        else
        {
            // Hide hud completely:
            buffHud.transform.parent.GetComponent <Image> ().enabled = false;
            buffHud.enabled   = false;
            healthHud.enabled = false;
            healthHud.transform.parent.GetComponent <Image> ().enabled = false;
            healthHudText.enabled = false;
        }

        // SCOREBOARD:
        if (Input.GetKey(KeyCode.Tab))
        {
            scoreBoard.SetActive(true);
            for (byte team = 0; team < 2; team++)
            {
                List <Player> players = GameManager.getPlayersOnTeam(team);
                for (int i = 0; i < scoreBoardPlayers[team].Count; i++)
                {
                    if (i < players.Count)
                    {
                        scoreBoardPlayers [team] [i].SetActive(true);
                        scoreBoardPlayers [team] [i].transform.Find("Text").GetComponent <Text> ().text = players [i].playerName;
                        Color c = scoreBoardPlayers [team] [i].GetComponent <Image> ().color;
                        if (players [i].playerObject != null)
                        {
                            scoreBoardPlayers [team] [i].GetComponent <Image> ().color = new Color(c.r, c.g, c.b, 1f);
                        }
                        else
                        {
                            scoreBoardPlayers [team] [i].GetComponent <Image> ().color = new Color(c.r, c.g, c.b, 0.2f);
                        }
                        scoreBoardKills [team] [i].text  = "" + players[i].kills;
                        scoreBoardDeaths [team] [i].text = "" + players[i].deaths;
                    }
                    else
                    {
                        scoreBoardPlayers [team] [i].SetActive(false);
                        scoreBoardKills [team] [i].text  = "";
                        scoreBoardDeaths [team] [i].text = "";
                    }
                }
            }
        }
        else
        {
            scoreBoard.SetActive(false);
        }

        // Display kill feed:
        for (int i = 0; i < killFeed.Count; i++)
        {
            if (GameManager.recentPlayerKillers.Count > i)
            {
                killFeed [i].parent.gameObject.SetActive(true);
                string killDisplay = "";
                if (GameManager.PlayerExists(GameManager.recentPlayerKillers [i]))
                {
                    killDisplay = GameManager.GetPlayer(GameManager.recentPlayerKillers [i]).playerName + " killed ";
                }
                if (GameManager.PlayerExists(GameManager.recentPlayerDeaths [i]))
                {
                    killFeed [i].GetComponent <Text> ().text = killDisplay + GameManager.GetPlayer(GameManager.recentPlayerDeaths [i]).playerName;
                }
            }
            else
            {
                killFeed [i].parent.gameObject.SetActive(false);
            }
        }

        // Class Selection Menu:
        if (OptionsMenu.classSelectionMenuOpen && Player.thisPlayer != null)
        {
            classSelectionMenu.SetActive(true);
            Color color;
            if (Player.thisPlayer.team == 0)
            {
                color = new Color(0, 0, 1f, 0.5f);
            }
            else if (Player.thisPlayer.team == 1)
            {
                color = new Color(1f, 0, 0, 0.5f);
            }
            else
            {
                color = new Color(1f, 1f, 1f, 0.5f);
            }

            classSelectionMenu.GetComponent <Image> ().color = color;
            for (byte i = 0; i < classSelectionTeams.Length; i++)
            {
                if (Player.thisPlayer.team == i)
                {
                    classSelectionTeams [i].color = new Color(classSelectionTeams [i].color.r, classSelectionTeams [i].color.g, classSelectionTeams [i].color.b, 1f);
                }
                else
                {
                    classSelectionTeams [i].color = new Color(classSelectionTeams [i].color.r, classSelectionTeams [i].color.g, classSelectionTeams [i].color.b, 0.6f);
                }
            }
            for (byte i = 0; i < classTypes.Count; i++)
            {
                if (Player.thisPlayer.team == 0)
                {
                    classTypes [i].gameObject.SetActive(true);
                    if (Player.thisPlayer.classNum == i)
                    {
                        classTypes [i].color = new Color(0.2f, 0.2f, 1f, 1f);
                    }
                    else
                    {
                        classTypes [i].color = new Color(0.7f, 0.7f, 1f, 0.8f);
                    }
                }
                else if (Player.thisPlayer.team == 1)
                {
                    classTypes [i].gameObject.SetActive(true);
                    if (Player.thisPlayer.classNum == i)
                    {
                        classTypes [i].color = new Color(1f, 0.2f, 0.2f, 1f);
                    }
                    else
                    {
                        classTypes [i].color = new Color(1f, 0.7f, 0.7f, 0.8f);
                    }
                }
                else
                {
                    classTypes [i].gameObject.SetActive(false);
                }
            }
        }
        else
        {
            classSelectionMenu.SetActive(false);
        }
    }