public static Branch InstantiateChild(Treee tree, Branch parentBranch, Transform parent, int parentDepth, float yAngle) { return(Branch.Instantiate(tree, parentBranch, parent, parentDepth, yAngle, tree.zAngle + Random.Range(-15, 15), Random.Range(tree.yOffsetMin, tree.yOffsetMax))); }
void InitFirstTree() { GameObject treeObject = (GameObject)Instantiate(treePrefab, firstTreePosition.transform.position, Quaternion.identity); treeObject.transform.parent = treeParent; treeObject.name = "FirstTree"; Treee tree = treeObject.GetComponent <Treee> (); tree.Root = Branch.InstantiateRoot(tree, null, tree.transform); }
public static Branch InstantiateRoot(Treee tree, Branch parentBranch, Transform parent) { return(Branch.Instantiate(tree, parentBranch, parent, 0, 0, Random.Range(-5, 5), 0)); }
public void AdjustChildren(int n, Treee tree) { Size *= Mathf.Pow(0.66f, n); depth -= n; this.tree = tree; foreach (Branch branch in branches) { branch.AdjustChildren(n, tree); } }
public void Attach(Treee tree) { var oldDepth = depth; parent.branches.Remove(this); AdjustChildren(depth - 1, tree); tree.Root = this; this.transform.parent = tree.transform; this.Size = Mathf.Pow(0.66f, oldDepth - 1); this.Grow(0); this.transform.localPosition = Vector3.zero; this.transform.localRotation = Quaternion.identity; }
public static Branch Instantiate(Treee tree, Branch parentBranch, Transform parent, int parentDepth, float yAngle, float zAngle, int yOffset) { GameObject obj = (GameObject)Instantiate(tree.branchPrefab); Branch branch = obj.AddComponent <Branch> (); branch.tree = tree; branch.parent = parentBranch; branch.depth = parentDepth + 1; obj.layer = LayerMask.NameToLayer("Branch"); obj.transform.parent = parent; obj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); obj.transform.localPosition = new Vector3(0, yOffset, 0); obj.transform.localRotation = Quaternion.Euler(0, yAngle, zAngle); return(branch); }
public bool placeTree(Vector3 mousePosition, Branch branch) { Treee originTree = branch.tree; Ray ray = Camera.main.ScreenPointToRay(mousePosition); // Get Mouse hit point on terrain RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000, terrainLayer)) { //if ((hit.point - originTree.transform.position).magnitude > originTree.Size * 5) { // return false; //} // check if allready trees are near mouse hitpoint var treesNearPoint = Physics.OverlapSphere(hit.point, 1, branchLayer); if (treesNearPoint.Length == 0) { GameObject treeObject = (GameObject)Instantiate(treePrefab); treeObject.transform.parent = treeParent; treeObject.name = "Tree"; treeObject.transform.position = hit.point; treeObject.transform.rotation = Quaternion.identity; Treee newTree = treeObject.GetComponent <Treee>(); branch.Attach(newTree); //newTree.Size = originTree.Size/2; //originTree.Size = originTree.Size/2; return(true); } } return(false); }