// Start is called before the first frame update protected virtual void Start() { spline = GetComponent <GrowingSpline>(); splineCollider = GetComponent <EdgeCollider2D>(); rays = new Ray2D[amountRays]; }
void CutTreeAt(int nodeIndex) { if (nodeIndex == 0) { return; } Vector2 position = GetPoint(nodeIndex); GameObject brokenTree = Instantiate(gameObject); GrowingSpline splineBrokenTree = brokenTree.GetComponent <GrowingSpline>(); foreach (BranchColonization branch in GetComponentsInChildren <BranchColonization>()) { if (branch.gameObject.transform.position.y > position.y) { branch.gameObject.transform.parent = brokenTree.transform; } } Rigidbody2D rb = brokenTree.AddComponent <Rigidbody2D>(); for (int i = 0; i < nodeIndex; i++) { splineBrokenTree.Spline.RemovePointAt(i); splineBrokenTree.enabled = false; } for (int i = SplineCount - 1; i < nodeIndex + 1; i--) { Spline.RemovePointAt(i); } }
// Start is called before the first frame update void Start() { tree = GetComponent <GrowingSpline>(); if (!branch.GetComponentInChildren <BranchController>()) { Debug.LogError("Branch object not correctly setup"); } if (!branch) { Debug.LogError("No branch prototype for the tree"); } }
public GrowingSpline GetHighestTree() { GrowingSpline highestTree = playerTree; float height = playerTree.GetPointWorldPos(playerTree.TopNodeIndex).y; if (height < leftTree.GetPointWorldPos(playerTree.TopNodeIndex).y) { highestTree = leftTree; } if (height < rightTree.GetPointWorldPos(playerTree.TopNodeIndex).y) { highestTree = rightTree; } return(highestTree); }
// Update is called once per frame void Update() { elapsedNewBranch += Time.deltaTime; if (elapsedNewBranch > timerNewBranch) { //Check if new branch float chance = Random.Range(0.0f, 100.0f); if (chance < (addedprobability += probabilityNewBranch)) { int nodeIndex = Random.Range(tree.SplineCount - includingNodes, tree.SplineCount); Vector2 p0, p1, p2, p3; tree.GetCubicBezierCurvePoints(nodeIndex, out p0, out p1, out p2, out p3); float percentageValue = Random.Range(0.0f, 1.0f); bool isLeft = (Random.value > 0.5f); Vector3 branchPosition = tree.GetPoint(p0, p1, p2, p3, percentageValue); branchPosition.z = 0.01f; //Needs to be behind the tree //branchSpline.GrowthDirection = tree.GetPointNormal(p0, p1, p2, p3, percentageValue, false); //TODO get the angle GameObject newBranch = Instantiate(branch, branchPosition + transform.position, Quaternion.Euler(0.0f, 0.0f, isLeft ? 90.0f : -90.0f), gameObject.transform); BranchColonization colonization = newBranch.GetComponent <BranchColonization>(); colonization.GenerateAttractors(amountAttractors, width, height); GrowingSpline branchSpline = newBranch.GetComponentInChildren <GrowingSpline>(); branchSpline.GrowthDirection = new Vector2(0.0f, 1.0f); branchSpline.SpriteShape = tree.SpriteShape; //Tangents are set in the branch growth addedprobability = 0.0f; } //Reset timer elapsedNewBranch -= timerNewBranch; } }
void Start() { spline = GetComponent <GrowingSpline>(); spriteRenderer = GetComponent <SpriteShapeRenderer>(); //collider = GetComponent<EdgeCollider2D>(); //TODO not safe }
List <ParticleCollisionEvent> rainCollisions = new List <ParticleCollisionEvent>(); // Not using this list... It is used for memory efficiency in the particle collision function void Start() { spline = GetComponent <GrowingSpline>(); }