// Start is called before the first frame update void Start() { rand = new System.Random(); cells = new CellularSimulation <int>(width, height); meshGen = GetComponent <MeshGenerator>(); cells.UpdateInPlace(cell => rand.Next(0, 100) <= percentFilled ? 1 : 0); meshGen.GenerateMesh(cells.Values(), 1); StartCoroutine(RunLoop()); }
IEnumerator RunLoop() { MeshGenerator meshGen = GetComponent <MeshGenerator>(); while (true) { cells.Update(Tick); meshGen.GenerateMesh(cells.Values(), 1); yield return(new WaitForSeconds(0.5f)); } }
void GenerateCave() { if (!useCustomSeed) { randomSeed = Time.time.ToString(); } rand = new System.Random(randomSeed.GetHashCode()); cells = new CellularSimulation <int>(width, height); cells.UpdateInPlace(InitialValue); for (int i = 0; i < smoothCount; i++) { cells.Update(Smooth); } MeshGenerator meshGen = GetComponent <MeshGenerator>(); meshGen.GenerateMesh(cells.Values(), 1); }