public Branch(Plant plant, Branch prnt, float length, float rotate_range, int d) { this.depth = d; this.RotOffset = Quaternion.Euler(Random.Range(-rotate_range, rotate_range), 0, Random.Range(-rotate_range, rotate_range)); this.parent = prnt; if (prnt == null) { this.vct = RotOffset * (Vector3.up * length); //set these to defaults since this is the root this.origin = Vector3.zero; } else { this.vct = prnt.RotOffset * RotOffset * (Vector3.up * length); //multiply by parent's rotation this.origin = prnt.origin + prnt.vct; //offset by parent's endpoint } bool FirstBranch = true; if (this.depth > 0) { while ((Random.Range(0.0f, 100.0f) / 100.0f < plant.branch_probability) || FirstBranch) { FirstBranch = false; Branch b = new Branch(plant, this, length * 0.8f, rotate_range, this.depth - 1); this.children.Add(b); plant.AddBranch(b); } } }