Ejemplo n.º 1
0
        protected IEnumerator UpdatePath()
        {
            if (Time.timeSinceLevelLoad < 0.5f)
            {
                yield return(new WaitForSeconds(0.5f));
            }
            if (rigid2d)
            {
                PathRequestManager2D.RequestPath(new PathRequest(rigid2d.position, target.position, targetBounds, OnPathFound));
            }
            else
            {
                PathRequestManager2D.RequestPath(new PathRequest(transform.position, target.position, targetBounds, OnPathFound));
            }

            float   sqrMoveThreshold = pathUpdateMoveThreshold * pathUpdateMoveThreshold;
            Vector3 targetPosOld     = target.position;

            while (true)
            {
                yield return(new WaitForSeconds(minPathUpdateTime));

                //print (((target.position - targetPosOld).sqrMagnitude) + "    " + sqrMoveThreshold);
                if ((target.position - targetPosOld).sqrMagnitude > sqrMoveThreshold)
                {
                    if (rigid2d)
                    {
                        PathRequestManager2D.RequestPath(new PathRequest(rigid2d.position, target.position, targetBounds, OnPathFound));
                    }
                    else
                    {
                        PathRequestManager2D.RequestPath(new PathRequest(transform.position, target.position, targetBounds, OnPathFound));
                    }
                    targetPosOld = target.position;
                }
            }
        }
Ejemplo n.º 2
0
 void Awake()
 {
     instance    = this;
     pathfinding = GetComponent <Pathfinder2D>();
 }