// Use this for initialization void Start() { boidCtrler.peachTreesManager = this; peachTrees = GetComponentsInChildren <PeachTreeLandingPtsCtrler>(); foreach (PeachTreeLandingPtsCtrler peachTree in peachTrees) { //peachTree.putTestingButterfly = true; peachTree.GenerateLandingPtsBasedOnBranches(); peachTree.SetPtsDirBasedOnObserver(Camera.main.transform.position); if (minNumLandingPts > peachTree.numPts) { minNumLandingPts = peachTree.numPts; } } if (numPeachTrees > 0 && boidCtrler != null) { PeachTreeLandingPtsCtrler peachTree = chooseTree(false); if (peachTree != null) { boidCtrler.PutBoidsOnTree(peachTree); } } //Invoke("FlyToSecondTree", 5); }
public void PutBoidsOnTree(PeachTreeLandingPtsCtrler peachTree) { boids.Clear(); foreach (Landable landable in peachTree.landablePts) { Transform landingPtTrans = landable.getTrans(); BoidFlocking boid = Instantiate(prefab, landingPtTrans.position, landingPtTrans.rotation) as BoidFlocking; boid.transform.parent = transform; boid.controller = this; landable.TargetBy(boid); boid.EnterState(BoidFlocking.State.perching); boids.Add(boid); } perchingTree = peachTree; }
public void FlyToTree(PeachTreeLandingPtsCtrler peachTree, bool scattered = true) { if (peachTree == perchingTree) { return; } foreach (Landable landable in perchingTree.landablePts) { landable.ReleaseAll(); } perchingTree = peachTree; if (scattered) { cohesionFactor = -Mathf.Abs(cohesionFactor); } else { cohesionFactor = Mathf.Abs(cohesionFactor); } foreach (BoidFlocking boid in boids) { Landable landable = peachTree.GetOneLandablePt(); if (landable == null) { Debug.Log("not enough landing pts QAQ"); break; } landable.TargetBy(boid); boid.EnterState(BoidFlocking.State.flocking); } if (cohesionFactor < 0) { Invoke("RecoverCoherent", 1); } }