// Use this for initialization void Start() { dashes.playerData = player.GetComponent <PlayerData>(); moneyText.playerData = player.GetComponent <PlayerData>(); moneyText.keybind = key.GetComponent <KeyBindings>(); healthText.playerData = player.GetComponent <PlayerData> (); levels.playerData = player.GetComponent <PlayerData> (); healthBar.playerData = player.GetComponent <PlayerData> (); weaponClass.playerData = player.GetComponent <PlayerData> (); start.key = key.GetComponent <KeyBindings>(); stats.playerData = player.GetComponent <PlayerData> (); stats.weapon = weapon.GetComponent <Weapon>(); // we want to make sure every element of the player's hud (except for shop, that's dealt with elsewhere) // is rendering to the correct layer. Transform[] allGUI = GetComponentsInChildren <Transform>(); // first get a collection of all the gui elements foreach (Transform gui in allGUI) { int playerNum = player.GetComponent <PlayerData>().GetPlayerNum(); //get the player info to set it to string playersLayer = "Player" + playerNum + "GUI"; if (gui.name != "Shop") // because, as we mentioned, this gets dealt with elsewhere { gui.gameObject.layer = LayerMask.NameToLayer(playersLayer); // and do the setting of the thing. } } }