///Conga Line Functions public void BecomeLeader() { bool become = true; amLeader = false; foreach (GameObject Creature in AllCreatures) { #region Check if Creature Deleted if (Creature == null || Creature.tag == "Player") { continue; } #endregion MonsterChecks creatureCheck = Creature.GetComponent <MonsterChecks>(); if (creatureCheck.AmLeader()) { //Debug.Log(Creature.name + " is the Leader of " + this.name); // set leader specialLeader = creatureCheck.specialLeader; // set MY target to my leader this.SetSpecialTarget(creatureCheck.specialTarget); // set my leader's target to ME creatureCheck.SetSpecialTarget(this.gameObject); become = false; } else if (creatureCheck.specialLeader != null && specialTarget == this.gameObject) { // set leader GameObject lead = creatureCheck.specialLeader; creatureCheck = lead.GetComponent <MonsterChecks>(); // set leader specialLeader = creatureCheck.specialLeader; // set MY target to my leader //this.SetSpecialTarget(creatureCheck.specialTarget); // set my leader's target to ME creatureCheck.SetSpecialTarget(this.gameObject); become = false; } } // no one is a leader, so be the leader if (become) { //Debug.Log(this.name + " is the Leader now!!!"); amLeader = true; specialTarget = this.gameObject; specialLeader = this.gameObject; } }
// Conga() // become the leader if no leader // otherwise, follow the last person in line public void Conga() { float congaSpeed = 4; if (Checks.AmLeader()) { // YOURE THE LEADER!! // GO GO GO Wander(2f, 2f); } else if (Checks.specialLeader != null) { // FOLLOW THE LEADER!! // LEFT RIGHT LEFT GameObject drone = Checks.ClosestDrone(); if (drone == null) { GameObject near = Checks.FollowTheLeader(); NavChase(near, congaSpeed, 2f); } else { //Behaviour.MoveTo(drone.transform.position, 3f, 1f); NavMelee(drone, congaSpeed); } } else if (Checks.specialTarget == null) { // still gotta conga!! // even with no leader } else { // decide leader if no one around if (!runningCoRoutine) { StartCoroutine(DecideLeader()); } } }