Beispiel #1
0
    IEnumerator UpdatePath()
    {
        if (Time.timeSinceLevelLoad < 0.3f || target == null)
        {
            yield return(new WaitForSeconds(0.3f));
        }
        CPathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPahFound));

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

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

            if ((target.position - targetPosOld).sqrMagnitude > sqrMoveThreshold)
            {
                CPathRequestManager.RequestPath(new PathRequest(transform.position, target.position, OnPahFound));
                targetPosOld = target.position;
            }
        }
    }
 private void Awake()
 {
     instance    = this;
     pathfinding = GetComponent <CPathFinder>();
 }