void CheckForValidAddBirdCollision(Collider2D other) { FlockAgent agent = other.GetComponentInParent <FlockAgent>(); // If a flock agent runs into this trigger, add all the birds in this flock to that flock if (agent != null && !flockManager.InFlock(agent)) { FlockManager otherFlock = agent.transform.root.GetComponent <FlockManager>(); if (otherFlock != null) { otherFlock.AddBirdsFromFlock(flockManager, flockManager.GetNumberOfAgents()); Destroy(gameObject); } } }
/* * Shoots off the given number of birds out of the flock in the given direction */ private void FireAgents(int numberOfBirds, Vector2 direction) { // Only fire the birds if there will be at least two birds remaining if (flockAgents.Count - numberOfBirds >= 2) { GameObject firedFlock = Instantiate(firedFlockPrefab, transform.position, Quaternion.LookRotation(direction, Vector3.up)); FlockManager firedFlockManager = firedFlock.GetComponent <FlockManager>(); if (firedFlockManager != null) { firedFlockManager.AddBirdsFromFlock(this, numberOfBirds); } else { Debug.LogError("Fired flock did not have a FlockManager component", firedFlockManager); } } }