Ejemplo n.º 1
0
 protected virtual void Update()
 {
     if (agent.isActiveAndEnabled)
     {
         Collider[] collidersInRange;
         cam.enabled = true;
         Plane[] planes = GeometryUtility.CalculateFrustumPlanes(cam);
         cam.enabled = false;
         //removed due to no combat
         // BaseAI enemyFound = CheckForEnemies(collidersInRange, planes);
         if (!agent.hasPath)
         {
             if (flagManager.isCarrying)
             {
                 agent.destination = myFlag.transform.position;
             }
             else
             {
                 agent.destination = enemyFlag.transform.position;
             }
         }
         // if (enemyFound) removed for no combat
         if (false)
         {
             //insert combat if needed
         }
         else
         {
             collidersInRange = Physics.OverlapSphere(transform.position, 100f, 1 << 10);
             BaseTrap trapFound = CheckForTraps(collidersInRange, planes);
             if (trapFound)
             {
                 int chanceToSee = Random.Range(0, 101);
                 if (chanceToSee <= 50)
                 {
                     trapFound.wasSeen = true;
                     trapFound.Invoke("ResetSeen", 5f);
                     canDisable = false;
                 }
                 else
                 {
                     trapFound.wasSeen = true;
                     if (dismantler.AICanDisable(this, trapFound))
                     {
                         agent.destination = trapFound.transform.position;
                         canDisable        = true;
                     }
                     else
                     {
                         trapFound.obstacle.enabled = true;
                         canDisable = false;
                     }
                     trapFound.Invoke("ResetSeen", 5f);
                 }
             }
             else
             {
                 collidersInRange = Physics.OverlapSphere(transform.position, 100f, 1 << 8);
                 GameObject resourceFound = CheckForResources(collidersInRange, planes);
                 if (resourceFound)
                 {
                     //move to resourceFound and collect
                     agent.destination = resourceFound.transform.position;
                     resourceFound     = null;
                 }
                 else
                 {
                     if (!flagManager.isCarrying)
                     {
                         agent.destination = enemyFlag.transform.position;
                     }
                     collidersInRange = Physics.OverlapSphere(transform.position, 100f, 1 << 11);
                     RaycastHit hit;
                     GameObject trapPlaceFound = CheckForSpot(collidersInRange, planes, out hit);
                     if (trapPlaceFound)
                     {
                         if (trapPlaceFound.tag == "pitPosition")
                         {
                             traps[0].SetTrap(hit, enemyTag);
                         }
                         else
                         {
                             RaycastHit normal;
                             Physics.Raycast(hit.point, hit.normal, out normal, 15f);
                             traps[1].SetTrap(hit, normal, enemyTag);
                         }
                         Destroy(trapPlaceFound);
                     }
                 }
             }
         }
     }
 }