// Update is called once per frame public void Generate() { if (!gen) { return; //Makes sure the chunk is properly initialized } if (!alive) { alive = true; gen.GenerateChunk(this); foreach (KeyValuePair <int, AsteroidData> p in flaggedAsteroids) { if (p.Key < 0) { SpawnAsteroidFromData(p.Value); } else if (p.Value.destroyed) { Destroy(asteroids[p.Key].gameObject, 0f); asteroids[p.Key] = null; } else { asteroids[p.Key].rigidbody2D.position = new Vector2(p.Value.posx, p.Value.posy); } } foreach (KeyValuePair <int, Asteroid> p in asteroids) { if (p.Value != null) { p.Value.gameObject.SetActive(true); } } if (eGen) { eGen.GenerateRandomEnemy(chunkx * chunkSize, chunky * chunkSize, chunkSeed); } } CancelInvoke(); Invoke("DestroyAsteroids", 30); }