Пример #1
0
 private void SetFormation(NPCInfo newLeader)
 {
     foreach (NPCInfo inf in NPCInfos)
     {
         inf.SetLeader(false);
     }
     if (generalBehavior == NPC.BehaviourType.Wander)
     {
         newLeader.SetLeader(true);
         newLeader.GetGameObject().GetComponent <NPC>().setFormation(newLeader.GetGameObject(), Vector3.zero);
         SetBestNPCForOffset(newLeader.GetGameObject(), LeftLine, RightLine);
     }
     else if (generalBehavior == NPC.BehaviourType.Track)
     {
         newLeader.SetLeader(true);
         newLeader.GetGameObject().GetComponent <NPC>().setFormation(newLeader.GetGameObject(), Vector3.zero);
         SetBestNPCForOffset(newLeader.GetGameObject(), LeftTrackV, RightTrackV);
     }
     else if (generalBehavior == NPC.BehaviourType.Attack)
     {
         newLeader.SetLeader(true);
         newLeader.GetGameObject().GetComponent <NPC>().setFormation(newLeader.GetGameObject(), Vector3.zero);
         SetBestNPCForOffset(newLeader.GetGameObject(), LeftAttackV, RightAttackV);
     }
 }
Пример #2
0
    private NPCInfo GetMiddleNPC()
    {
        Vector3 average = Vector3.zero;

        for (int i = 0; i < NPCInfos.Count; ++i)
        {
            average += NPCInfos[i].GetGameObject().transform.position;
        }
        average /= NPCInfos.Count;
        NPCInfo res = NPCInfos[0];

        for (int i = 0; i < NPCInfos.Count; ++i)
        {
            float dist0 = Mathf.Sqrt(Mathf.Pow(average.x - res.GetGameObject().transform.position.x, 2) + Mathf.Pow(average.z - res.GetGameObject().transform.position.z, 2));
            float dist1 = Mathf.Sqrt(Mathf.Pow(average.x - NPCInfos[i].GetGameObject().transform.position.x, 2) + Mathf.Pow(average.z - NPCInfos[i].GetGameObject().transform.position.z, 2));
            if (dist1 < dist0)
            {
                res = NPCInfos[i];
            }
        }

        return(res);
    }