예제 #1
0
    protected void ComeMineMe(UnitComponent unit)   // should probs make a delegate. // Should probably move this to a manager script for this.
    {
        if (unit == null)
        {
            return;
        }

        Vector3 selectedUnitPosition = unit.transform.position;

        List <MapNode> neighbourListUnder = referenceTerrain.GetNeighbours(dBUnderlyingTile.nodeReference);

        foreach (MapNode neighbour in neighbourListUnder)
        {
            if (!neighbour.walkableNode)
            {
                neighbourListUnder.Remove(neighbour);
                continue;
            }
            int     xCoord     = neighbour.lvlGrid_X;
            int     zCoord     = neighbour.lvlGrid_YorZ;
            Vector3 testCoords = new Vector3(xCoord, 0, zCoord);

            PathFinderRequestManager.RequestPath(new PathRequest(selectedUnitPosition, testCoords, PathCompare));
        }
    }
 public void SetDestinationPos(Vector2 pos)
 {
     m_targetPos         = pos;
     m_randomGeneratePos = false;
     StopCoroutine("FollowFoundPath");
     m_path = null;
     PathFinderRequestManager.RequestPath(new PathRequest(transform.position, m_targetPos, PathFound));
 }
 private void Awake()
 {
     if (instance != null)
     {
         Destroy(this);
         return;
     }
     instance     = this;
     m_pathFinder = new PathFinder(GetComponent <PathGrid>());
 }
 private void Update()
 {
     if (m_path == null && m_randomGeneratePos && Time.time >= m_startWaitingTime + waitTimeBetweenRandomPos)
     {
         m_targetPos = new Vector2(Random.Range(randomPatrolArea.xMin, randomPatrolArea.xMax), Random.Range(randomPatrolArea.yMin, randomPatrolArea.yMax));
         if (!Physics.Raycast(new Vector3(m_targetPos.x, m_targetPos.y, 1), Vector3.forward))
         {
             PathFinderRequestManager.RequestPath(new PathRequest(transform.position, m_targetPos, PathFound));
         }
     }
 }
    //----------------------------------------------------------------------------------------------------------------
    //----------------------------------------------------------------------------------------------------------------

    #region PATH MANAGEMENT

    public void SendPathRequestForUnit(RaycastHit hit, int listCount)
    {
        Debug.Log("RMB clicked, Move order received for: " + gameObject.name);

        whereAmI = gameObject.transform.position;
        goThere  = hit.collider.transform;
        Vector3 goThereModif = new Vector3(goThere.position.x, 0, goThere.position.z);
        //Debug.Log(goThere.position +"| original goThereModif: "+ goThereModif);

        GroundTileScript gts = hit.collider.GetComponent <GroundTileScript>();  // retrieve from map node note ground tile script

        if (!(gts.transform.position == whereAmI) && unitReference.isSelected == true)
        {
            goThereModif = ScanDestination(hit, listCount, 0);

            //destinationIndicator.transform.position = goThereModif + new Vector3(0, 0.2f, 0);
            //destinationIndicator.SetActive(true);

            //Debug.Log(goThere.position + "| POSTSCAN Modif: " + goThereModif);
            //Debug.Log("Unit " + gameObject.name + " is at: " + gameObject.transform.position.x + "; " + gameObject.transform.position.z + " and wants to head to: " + goThereModif.x + "; " + goThereModif.z);

            PathFinderRequestManager.RequestPath(new PathRequest(whereAmI, goThereModif, OnPathFound)); // changed in accordance with new pf manager version.
        }
    }
예제 #6
0
 private void Awake()
 {
     instance        = this;
     pathfinderLogic = gameObject.GetComponent <Pathfinding_a3>();
     //Debug.Log(gameObject.name + " has awoken");
 }