This commit is contained in:
vis2k 2019-04-03 16:05:45 +02:00
parent 370f66b9b4
commit e9717d87ad

View File

@ -232,14 +232,14 @@ public static void BalancePrefabs(GameObject prefab, int amount, Transform paren
// instantiate until amount // instantiate until amount
for (int i = parent.childCount; i < amount; ++i) for (int i = parent.childCount; i < amount; ++i)
{ {
GameObject go = GameObject.Instantiate(prefab); GameObject go = Instantiate(prefab);
go.transform.SetParent(parent, false); go.transform.SetParent(parent, false);
} }
// delete everything that's too much // delete everything that's too much
// (backwards loop because Destroy changes childCount) // (backwards loop because Destroy changes childCount)
for (int i = parent.childCount-1; i >= amount; --i) for (int i = parent.childCount-1; i >= amount; --i)
GameObject.Destroy(parent.GetChild(i).gameObject); Destroy(parent.GetChild(i).gameObject);
} }
void OnUI() void OnUI()