- Home /
"Foreach" in an Array?
Hey! I am trying to use an array like I would use a list; in this case I am trying to find a specific outlier and destroy it. Would be much appreciated if someone could help me out!
if(LoadNumber == 0)
{
if(inLobby == true)
{
MainMenuGUI.Instance.ToMenu("Lobby");
GameObject[] NetworkManagers;
NetworkManagers = GameObject.FindGameObjectsWithTag("NetworkManager");
foreach(NetworkManagers nm in NetworkManagers)
{
if(nm.transform.GetComponent<NetworkManager>().PlayerList.count <= 0)
{
Destroy(nm);
}
}
}
}
Comment
Best Answer
Answer by SirCrazyNugget · Mar 24, 2014 at 09:31 AM
You should have something along the lines of:
GameObject[] NetworkManagers;
NetworkManagers = GameObject.FindGameObjectsWithTag("string of wanted tag");
foreach(GameObject nm in NetworkManagers){
if(nm.transform.GetComponent<NetworkManagers>().PlayerList.count <= 0){
Destroy(nm);
}
}
Please indicate what is different in your code from his.
foreach(GameObject nm in Network$$anonymous$$anagers){
the type is now GameObject
Hi fafase, my answer wouldn't work so I deleted it, thanks to point it out.
How the hell could I have forgotten how to do that -.- thanks!