コード例 #1
0
ファイル: Unit2D.cs プロジェクト: reakain/Broom-Racing
        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;
                }
            }
        }
コード例 #2
0
 void Awake()
 {
     instance    = this;
     pathfinding = GetComponent <Pathfinder2D>();
 }