void Update() { if (IsPaused) { return; } if (!HasReachedTarget) { // Move the bandit towards the target, and prevent over shooting. transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime); // If the target position has been reached, then stop moving. if (transform.position == targetPosition) { // If we have a path, and haven't reached the end, then start moving towards the next node. // Otherwise, we've reached the target and can stop. if (pathEnumerator != null && pathEnumerator.MoveNext()) { SetTargetNode(pathEnumerator.Current, false); } else { HasReachedTarget = true; OnEndMove.Invoke(); if (OnTargetReached != null) { OnTargetReached(); OnTargetReached = null; } } } } }
// TODO Change to use promises DLL public void MoveToNode(IGraphNode node, TargetReachedHandler callback, int movementLimit = -1) { OnTargetReached = callback; MoveToNode(node, movementLimit); }