Ejemplo n.º 1
0
    private void MoveTowardsOrigin()
    {
        if (pathfinding.HasPath())
        {        //If we have no path then request one
            //First, if we are too close (and can see the target) then we need to create some distance!
            if (GetDistanceToOrigin() < 4 && CheckLineOfSight(eyes.position, pointOfOrigin))
            {
                run = GetDirectionToOrigin().x < 0 ? -1 : 1;
                return;
            }

            if (IsPathToOriginStillValid())
            {
                if (FollowPath())
                {
                    if (verboseDebug)
                    {
                        Debug.Log(name + ": " + enemyState + ": I reached the end of my path so requested a new one");
                    }
                }
            }
            else
            {
                if (verboseDebug)
                {
                    Debug.Log(name + ": " + enemyState + ": my path was no longer valid so I requested a new one");
                }
                pathfinding.SetPathUnvalid();
            }
        }
        else
        {        //We have a path
            //First, if we are too close then we need to create some distance!

            if (!pathfinding.hasRequestedPath)
            {
                pathfinding.RequestPath(pointOfOrigin);
                //Debug.Log("Requested Path");
            }
            if (pointOfOrigin.x > transform.position.x)
            {
                run = 1;
            }
            else
            {
                run = -1;
            }
        }
    }
Ejemplo n.º 2
0
    IEnumerator TimerForSwitchTarget()
    {
        _timerChangeTarget = true;
        yield return(new WaitForSeconds(5f));

        _pathAgent.pathfindingTarget = _pathScript.GroundNodes[Random.Range(0, _pathScript.GroundNodes.Count)].gameObject;
        _pathAgent.RequestPath(_pathAgent.pathfindingTarget.transform.position + new Vector3(0, 3, 0));
        //Debug.Log(_pathAgent.pathfindingTarget.transform.position + new Vector3(0,3,0));
        _timerChangeTarget = false;
    }
Ejemplo n.º 3
0
 private void spawnUnit()
 {
     for (int i = spawns.Count; i > 0; i--)
     {
         if (spawns[i - 1] == null)
         {
             spawns.Remove(spawns[i - 1]);
         }
     }
     if (spawns.Count < spawnAmount)
     {
         GameObject newGameObject = (GameObject)Instantiate(Resources.Load("pathfindChaseAi"), new Vector3(transform.position.x, transform.position.y, 0.0f), Quaternion.identity) as GameObject;
         spawns.Add(newGameObject);
         PathfindingAgent newCharScript = newGameObject.transform.GetComponent <PathfindingAgent>();
         newCharScript.RequestPath((Vector3)target.transform.position);
     }
 }