コード例 #1
0
        public void Follow(PathData pathData, float moveSpeed, FollowType followType, FollowDirection followDirection)
        {
            this.pathData = pathData;
            this.moveSpeed = moveSpeed;
            this.followType = followType;
            this.followDirection = followDirection;

            StopFollowing();

            var closestLineIndex = GetClosestLineIndex(_transform.position);
            _currentIndex = GetClosestPointIndex(closestLineIndex * 20, _transform.position);
            StartCoroutine("FollowPath");
        }
コード例 #2
0
        public void FollowToPoint(PathData pathData, float moveSpeed, Vector2 targetPos)
        {
            this.pathData = pathData;
            this.moveSpeed = moveSpeed;
            this.followType = FollowType.Once;

            StopFollowing();

            var closestLineIndex = GetClosestLineIndex(_transform.position);
            _currentIndex = GetClosestPointIndex(closestLineIndex * 20, _transform.position);
            closestLineIndex = GetClosestLineIndex(targetPos);
            var targetIndex = GetClosestPointIndex(closestLineIndex * 20, targetPos);
            this.followDirection = (_currentIndex < targetIndex) ? FollowDirection.Forward : FollowDirection.Backward;
            StartCoroutine("FollowPathToPoint", targetIndex);
        }