void Start() { if (m_leader == null && m_leaderInput != null) { m_leader = m_leaderInput.GetComponent <FlockLeader> (); } m_leader.m_flock.Add(this); m_rb = this.gameObject.GetComponent <Rigidbody> (); }
public void SetLeader(FlockLeader newLeader) { if (LeaderChangeTimer > 0) { return; } Leader?.Followers?.Remove(this); newLeader.Followers.Add(this); Leader = newLeader; GetComponent <BirdStealer>().Leader = newLeader; transform.parent = newLeader.transform.parent; LeaderChangeTimer = LeaderChangeCooldown; }
void spawnFlock(Vector3 position, FlockLeader leaderPrefab, int flockSize) { var leader = Instantiate(leaderPrefab, position, Quaternion.identity); var container = new GameObject("flock container " + index++).transform; leader.transform.parent = container; for (int i = 0; i < flockSize; i++) { var follower = Instantiate ( FollowerPrefab, position + Random.insideUnitSphere * leader.InitialMaxRadius, Quaternion.identity, container ); follower.SetLeader(leader); } }
void switchTarget() { if (RandomExtra.Chance(PlayerGuaranteedTargetChance)) { target = FindObjectOfType(typeof(Player)) as FlockLeader; return; } var potentialTargets = (FindObjectsOfType(typeof(FlockLeader)) as FlockLeader[]).ToList(); potentialTargets.Remove(this); Func <FlockLeader, bool> inRange = fl => Vector3.Distance(fl.transform.position, transform.position) <= DesiredMaximumDistance; if (!potentialTargets.Where(fl => fl != target).Any(inRange)) { target = potentialTargets.PickRandom(); } else { target = potentialTargets.Where(fl => fl != target).Where(inRange).ToList().PickRandom(); } }