void SetupFlammableTerrain(MeshCollider mesh) { float xdistance = mesh.bounds.max.x - mesh.bounds.min.x; float zdistance = mesh.bounds.max.z - mesh.bounds.min.z; int numberFiresRow = Mathf.FloorToInt(xdistance / meshFireDistanceBetween) + 1; int numberColumns = Mathf.FloorToInt(zdistance / meshFireDistanceBetween) + 1; int numberOfFires = numberFiresRow * numberColumns; for (int i = 0; i < numberOfFires; i++) { float xTransform = Mathf.Clamp( mesh.bounds.min.x + (i % numberFiresRow * meshFireDistanceBetween) + Random.Range(-1, 1f) , mesh.bounds.min.x , mesh.bounds.max.x); float zTransform = Mathf.Clamp( mesh.bounds.min.z + Mathf.FloorToInt(i / numberFiresRow) * meshFireDistanceBetween + Random.Range(-1, 1f) , mesh.bounds.min.z , mesh.bounds.max.z); Ray ray = new Ray(new Vector3(xTransform, mesh.bounds.max.y + 1f, zTransform), Vector3.down); RaycastHit[] hits = Physics.RaycastAll(ray); float yTransform = 0; foreach (RaycastHit hit in hits) { if (hit.collider == mesh) { yTransform = hit.point.y; } } GameObject newFireSystem = Instantiate(fireSystemPrefab, new Vector3(xTransform, yTransform, zTransform), fireSystemPrefab.transform.rotation, mesh.transform); SetupFireSystem(newFireSystem.GetComponent <FireSystem>(), mesh.GetComponentInParent <Renderer>().sharedMaterial); Vector3 worldScale = newFireSystem.transform.lossyScale; newFireSystem.GetComponent <SphereCollider>().radius /= Mathf.Max(worldScale.x, Mathf.Max(worldScale.y, worldScale.z)); fireSystems.Add(newFireSystem.GetComponent <FireSystem>()); } }