void FractalTree(int section, float angle, Transform parent, Vector3 posOffset = default(Vector3), Vector3 rotation = default(Vector3))
{
//当剩余分形次数为0时,退出
if (section == 0)
{
return;
}
//以上一个方块为当前方块父物体,并调整当前方块的位置与角度
GameObject branch = Instantiate(normalCube, parent.transform.position + parent.transform.up, new Quaternion(), parent);
branch.transform.position += posOffset;
rotation = rotation.normalized * angle;
branch.transform.Rotate(rotation, Space.Self);
//这里是设置树枝的长度,我把设置成section + 2,让它随着树的深度递减
GameObject[] bramches = new GameObject[section + 2];
bramches[0] = Instantiate(normalCube, branch.transform.position + branch.transform.up, new Quaternion(), branch.transform);
for (int i = 1; i < section + 2; i++)
{
//从前一个方块中衍生出后面的方块,形成一根树枝