void Go(bool first = false) { //pick a target _target = Target.AllTargets[Random.Range(0, Target.AllTargets.Count)]; _mat.color = Color.white; if (_target != null) { PathRequestManager.RequestPath(transform.position, _target.transform.position, OnPathFound); } }
IEnumerator UpdatePath() { if (Time.timeSinceLevelLoad < .3f) { yield return(new WaitForSeconds(.3f)); } PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, false, 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) { PathRequestManager.RequestPath(new PathRequest(transform.position, target.position, false, OnPathFound)); targetPosOld = target.position; } } }