// Update is called once per frame void Update() { if (parameters_change()) { Debug.Log("jauwhsd"); foreach (GameObject child in children) { if (recursion_iterations > 0) { RecursiveInstantiator child_inst = child.GetComponent <RecursiveInstantiator>(); child.SendMessage("DestroyRecursive", child_inst.get_children()); } else { Destroy(child); } } if (recursion_iterations > 0) { children.Clear(); for (int i = 0; i < split_number; i++) { GameObject branch_copy = Instantiate(gameObject); children.Add(branch_copy); RecursiveInstantiator branch_copy_rec_inst = branch_copy.GetComponent <RecursiveInstantiator>(); branch_copy_rec_inst.recursion_iterations -= 1; Vector3 arguments = new Vector3((float)i, branch_scale, branch_angle_rotation); branch_copy.SendMessage("Generated", arguments); } } } }
void Update() { //Creates a new tree via recursion if (Input.GetKeyDown("q")) { pos = new Vector3(Random.Range(-2, 2), 4, Random.Range(-2, 2)); Instantiate(tree, pos, Quaternion.identity); Debug.Log("done"); RecursiveInstantiator.setBooleanFlag(true); } //Creates a new TreeHolder with an EmptyTreeHolder tag to allow a tree to grow in it if (Input.GetKeyDown("t")) { pos = new Vector3(Random.Range(-2, 2), 4, Random.Range(-2, 2)); TreeHolder.tag = "EmptyTreeHolder"; Instantiate(TreeHolder, pos, Quaternion.identity); } //"Closes" the current TreeHolder by preventing any more trees to grow inside it //Enables the boolean flag that allows the tree to resize the prefab if (Input.GetKeyDown("r")) { GameObject.FindGameObjectWithTag("EmptyTreeHolder").tag = "FilledTreeHolder"; } }
public void DestroyRecursive(List <GameObject> children) { foreach (GameObject child in children) { //Debug.Log("jauwhsd"); RecursiveInstantiator child_inst = child.GetComponent <RecursiveInstantiator>(); //child_inst.updateNode(this.gameObject); child.SendMessage("DestroyRecursive", child_inst.get_children()); //i++; } Destroy(this.gameObject); }
// Use this for initialization void Start() { initial_recursion_iterations = recursion_iterations; initial_split_number = split_number; initial_branch_scale = branch_scale; initial_branch_angle_rotation = branch_angle_rotation; if (recursion_iterations > 0) { int number_of_branches = split_number; if (root != null && recursion_iterations < root.GetComponent <RecursiveInstantiator>().recursion_iterations - 1) { number_of_branches = Random.Range(2, split_number); } for (int i = 0; i < number_of_branches; i++) { GameObject branch_copy = null; branch_copy = Instantiate(gameObject); children.Add(branch_copy); RecursiveInstantiator branch_copy_rec_inst = branch_copy.GetComponent <RecursiveInstantiator>(); branch_copy_rec_inst.recursion_iterations -= 1; if (root == null) { branch_copy_rec_inst.root = gameObject; } else { branch_copy_rec_inst.root = this.root; } Vector3 arguments = new Vector3((float)i, branch_scale, branch_angle_rotation); branch_copy.SendMessage("Generated", arguments); } } Debug.Log(root); if (root != null && recursion_iterations < root.GetComponent <RecursiveInstantiator>().recursion_iterations - 1) { //GameObject leaf = Instantiate(leaves); //children.Add(leaf); leaves.SetActive(true); } if (root != null) { this.gameObject.SetActive(false); } }
// Start is called before the first frame update void Start() { rec_inst = GetComponent <RecursiveInstantiator>(); children = rec_inst.get_children(); final_scale = this.transform.localScale.y; }