public IEnumerator GetPathToMouse()
    {
        waiting = true;
        GridCell targetCell = navMeshInstance.GetClosetOpenCell(this.transform.position, Vector3.zero);
        GridCell startCell  = navMeshInstance.GetClosetOpenCell(Vector3.zero, this.transform.position);

        if (targetCell != null && startCell != null)
        {
            path = navMeshInstance.GetPathBetweenTwoPoints(startCell.position, targetCell.position);
            yield return(new WaitForSeconds(0.1f));
        }
        waiting = false;
    }
Esempio n. 2
0
    /// <summary>
    /// Carefull! This overwrites the existing path
    /// </summary>
    /// <param name="target"></param>
    protected bool SetPathToPoint(Vector3 target)
    {
        // Get the closest cell to the target and then path to that target
        GridCell targetCell = navMeshInstance.GetClosetOpenCell(target, this.transform.position);

        if (targetCell != null)
        {
            //Debug.Log(this.transform.position + " " + target + " Closest target pos: " + targetCell.position);
            path = navMeshInstance.GetPathBetweenTwoPoints(this.transform.position, targetCell.position);
            GetNextPointTarget();
            return(path != null);
        }
        return(false);
    }