diff --git a/Episode 10 - threading/Assets/Scripts/Unit.cs b/Episode 10 - threading/Assets/Scripts/Unit.cs index 65458d6..507f83c 100644 --- a/Episode 10 - threading/Assets/Scripts/Unit.cs +++ b/Episode 10 - threading/Assets/Scripts/Unit.cs @@ -54,6 +54,8 @@ IEnumerator FollowPath() { transform.LookAt (path.lookPoints [0]); float speedPercent = 1; + + int pathHash = path.GetHashCode(); while (followingPath) { Vector2 pos2D = new Vector2 (transform.position.x, transform.position.z); @@ -82,6 +84,11 @@ IEnumerator FollowPath() { yield return null; + // Check if the path has changed + if (path.GetHashCode() != pathHash) { + followingPath = false; + } + } }