public void SetPath(Vector3[] targets, float speed, float reachDistance) { if ((targets.Length == 0) || (this.lastSetPathTargets == targets) || (Time.time - this.lastPathSetTime < 0.5f)) { return; } this.lastSetPathTargets = targets; this.speed = speed; this.reachDistance = reachDistance; this.lastPathSetTime = Time.time; this.changeAngle = true; this.onPathReached = () => { this.Stop(); Vector3 target = Vector3.zero; do { target = targets[Random.Range(0, targets.Length)]; }while ((path != null) && (path.vectorPath.Last() == target)); this.seeker.StartPath(this.rb.position, target, OnPathFound); }; this.onPathReached(); }
public void GoTo(Vector3 target, float speed, float reachDistance, bool changeAngle) { this.changeAngle = changeAngle; if ((Time.time - this.lastPathSetTime < 0.5f) || (Vector2.Distance(this.rb.position, target) < reachDistance)) { return; } this.speed = speed; this.reachDistance = reachDistance; this.lastPathSetTime = Time.time; this.seeker.StartPath(this.rb.position, target, OnPathFound); this.onPathReached = () => { this.Stop(); }; }