예제 #1
0
        public void Execute()
        {
            if (_pause)
            {
                return;
            }

            if (_movementNodeGenerated == false)
            {
                _movementAI.ClearPath();
                _movementAI.CreatePathTo(_pathfindData.Location);
                _movementNodeGenerated = true;
            }

            Character2D character    = _pathfindData.Character;
            var         movementPath = _movementAI.GetCurrentPath();

            if (movementPath.Count <= 0)
            {
                character.Animator.SetBool("IDLE", true);
                SetCompleted();
                return;
            }

            Vector2 targetPosition = movementPath[movementPath.Count - 1].Position;
            float   distance       = targetPosition.x - character.transform.position.x;

            if (distance < 0.0f)
            {
                character.FaceRight();
                distance = -1.0f;
                character.Animator.SetBool("IDLE", false);
            }
            else if (distance > 0.0f)
            {
                character.FaceLeft();
                distance = 1.0f;
                character.Animator.SetBool("IDLE", false);
            }
            else
            {
                character.Animator.SetBool("IDLE", true);
            }

            _movementAI.CheckAndMoveToNextPathNode();
            character.transform.position = new Vector3(character.transform.position.x + (character.WalkSpeed * distance), character.transform.position.y, character.transform.position.z);
        }