well im having problems to initialize coroutines
in the start function i got this :
void Start()
{
rotationSpeed = Random.Range(-maxRotationSpeed, maxRotationSpeed);
if (materials == null)
{
InitializeMaterials();
}
gameObject.AddComponent<MeshFilter>().mesh = meshes[Random.Range(0, meshes.Length)]; ;
gameObject.AddComponent<MeshRenderer>().material = materials[depth, Random.Range(0, 2)];
//GetComponent<MeshRenderer>().material.color = Color.Lerp(Color.white, Color.blue, (float)depth / maxDepth);
if (depth < maxDepth && randomSpawn)
{
StartCoroutine(CreateChildrenRandom());
}
if (depth < maxDepth && randomSpawn == false)
{
StartCoroutine(CreateChildren());
}
transform.Rotate(Random.Range(-maxTwist, maxTwist), 0f, 0f);
}
what im trying to do is to validate 1 of the ifs above but for an unknown reason it tries to start both or just the createChildren courutine
private IEnumerator CreateChildrenRandom()
{
if (Random.value < spawnProbability)
{
for (int i = 0; i < childDirections.Length; i++)
{
yield return new WaitForSeconds(Random.Range(0.1f, 0.5f));
new GameObject("Fractal Child").AddComponent<Fractal>().Initialize(this, i);
}
}
Debug.Log("make1");
}
private IEnumerator CreateChildren()
{
for (int i = 0; i < childDirections.Length; i++)
{
yield return new WaitForSeconds(Random.Range(0.1f, 0.5f));
new GameObject("Fractal Child").AddComponent<Fractal>().Initialize(this, i);
}
Debug.Log("make2");
}
plz if you can help me with this it would be much apreciated