/// <summary> /// The leader has changed. Update the leader. /// </summary> private void UpdateLeader() { // If the leader is null then the current agent is the leader. if (leader.Value == null) { AddAgentToGroup(Owner, 0); #if DEATHMATCH_AI_KIT_PRESENT if (TeamManager.IsInstantiated) { TeamManager.SetLeader(gameObject, true); } #endif if (waitTime.Value == 0) { StartFormation(); } else { StartCoroutine(WaitForGroupFormation()); } } else { var leaderTrees = leader.Value.GetComponents <Behavior>(); if (leaderTrees.Length > 1) { for (int i = 0; i < leaderTrees.Length; ++i) { if (leaderTrees[i].Group == leaderGroupIndex.Value) { leaderTree = leaderTrees[i]; break; } } } else if (leaderTrees.Length == 1) { leaderTree = leaderTrees[0]; } if (leaderTree != null) { sendListenerEvent = true; } #if DEATHMATCH_AI_KIT_PRESENT if (TeamManager.IsInstantiated) { // If the leader tree is null then the leader is a player-controlled character. formationIndex = TeamManager.AddToFormation(leader.Value, Owner) + (leaderTree == null ? 1 : 0); } #endif } prevLeader = leader.Value; }