Beispiel #1
0
    public void relocate(FreeFormation freeFormation, Transform newFollow)
    {
        Drone[] drones = new Drone[transform.childCount];

        int i = 0;

        Drone d;

        while (d = transform.GetComponentInChildren <Drone>())
        {
            drones[i]          = d;
            d.transform.parent = null;
            DestinationFormation destionation = d.GetComponent <DestinationFormation>();
            destionation.destination = this;
            remove_drone(d);
            i++;
        }
        follow             = newFollow;
        transform.position = newFollow.position;

        for (int j = 0; j < i; j++)
        {
            freeFormation.add_drone(drones[j]);
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        int children_count = transform.childCount;

        if (Time.deltaTime != 0f)
        {
            for (int i = 0; i < children_count; i++)
            {
                Transform                   child = transform.GetChild(i);
                DestinationFormation        dest  = child.GetComponent <DestinationFormation>();
                UnityEngine.AI.NavMeshAgent agent = child.GetComponent <UnityEngine.AI.NavMeshAgent>();
                if (Vector3.Distance(child.position, dest.destination.transform.position) <= dest.transfer_distance)
                {
                    agent.Stop();
                    agent.enabled = false;
                    dest.destination.add_drone(child.GetComponent <Drone>());
                    i--;
                    children_count--;
                }
                else if (Vector3.Distance(dest.destination.transform.position, agent.destination) > dest.transfer_distance || Vector3.Distance(dest.destination.transform.position, agent.destination) > Vector3.Distance(child.position, agent.destination))
                {
                    agent.SetDestination(dest.destination.transform.position);
                }
            }
        }
    }
Beispiel #3
0
    public void move_drone(Drone d, Formation destination)
    {
        if (d.GetComponent <DestinationFormation>() == null)
        {
            d.gameObject.AddComponent <DestinationFormation>();
        }
        DestinationFormation destinationFormation = d.GetComponent <DestinationFormation>();

        destinationFormation.destination = destination;
        add_drone(d);
    }
Beispiel #4
0
 public override void add_drone(Drone d)
 {
     if (d.GetComponent <DestinationFormation>() != null)
     {
         d.GetComponent <UnityEngine.AI.NavMeshAgent>().enabled = true;
         DestinationFormation        dest  = d.GetComponent <DestinationFormation>();
         UnityEngine.AI.NavMeshAgent agent = d.GetComponent <UnityEngine.AI.NavMeshAgent>();
         d.transform.SetParent(transform, true);
         agent.SetDestination(dest.destination.transform.position);
     }
 }