CharacterFollowTargetCommand.cs 1.1 KB

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