CharacterMoveToPositionCommand.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Core;
  5. namespace KairoEngine.CharacterSystem
  6. {
  7. public class CharacterMoveToPositionCommand : ICommand
  8. {
  9. CharacterController character;
  10. Vector3 targetPosition;
  11. float speed;
  12. float animationSpeed;
  13. float stoppingDistance;
  14. public CharacterMoveToPositionCommand(CharacterController character, Vector3 targetPosition, float speed, float animationSpeed = 1f, float stoppingDistance = 1f)
  15. {
  16. this.character = character;
  17. this.targetPosition = targetPosition;
  18. this.speed = speed;
  19. this.animationSpeed = animationSpeed;
  20. this.stoppingDistance = stoppingDistance;
  21. }
  22. public void Execute()
  23. {
  24. CharacterMoveToPositionAction action = new CharacterMoveToPositionAction(character, targetPosition, speed, animationSpeed, stoppingDistance);
  25. ActionController actionController = character.GetComponent<ActionController>();
  26. if(actionController.HasAction(action) == false)
  27. {
  28. actionController.AddAction(action);
  29. }
  30. else
  31. {
  32. actionController.ChangeAction(action);
  33. }
  34. }
  35. }
  36. }