Beispiel #1
0
 // if we're going to collect a resource, move away if we collide with another unit
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("Unit"))
     {
         if (state == UnitState.MoveToResource)
         {
             if (Vector3.Distance(transform.position, curResourceSource.transform.position) < 2)
             {
                 navAgent.SetDestination(UnitMover.GetUnitDestinationAroundResource(curResourceSource.transform.position));
             }
         }
     }
 }
Beispiel #2
0
    // find a nearby resource to gather from
    void FindNewResource()
    {
        ResourceSource resourceToGet = playerAI.GetClosestResource(transform.position);

        if (resourceToGet != null)
        {
            unit.GatherResource(resourceToGet, UnitMover.GetUnitDestinationAroundResource(resourceToGet.transform.position));
        }
        else
        {
            PursueEnemy();
        }
    }
Beispiel #3
0
 //pozivanje funkcije koja prikuplja resurse
 void UnitsGatherResource(ResourceSource resource, Unit[] units)
 {
     if (units.Length == 1)
     {
         units[0].GatherResource(resource, UnitMover.GetUnitDestinationAroundResource(resource.transform.position));
     }
     else
     {
         Vector3[] destinations = UnitMover.GetUnitGroupDestinationsAroundResource(resource.transform.position, units.Length);
         for (int x = 0; x < units.Length; x++)
         {
             units[x].GatherResource(resource, destinations[x]);
         }
     }
 }
Beispiel #4
0
    // called when we command units to gather a resource
    void UnitsGatherResource(ResourceSource resource, Unit[] units)
    {
        // are just selecting 1 unit?
        if (units.Length == 1)
        {
            units[0].GatherResource(resource, UnitMover.GetUnitDestinationAroundResource(resource.transform.position));
        }
        // otherwise, calculate the unit group formation
        else
        {
            Vector3[] destinations = UnitMover.GetUnitGroupDestinationsAroundResource(resource.transform.position, units);

            for (int x = 0; x < units.Length; x++)
            {
                units[x].GatherResource(resource, destinations[x]);
            }
        }
    }