CharacterAimAction.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using RootMotion.FinalIK;
  5. using KairoEngine.Core;
  6. namespace KairoEngine.CharacterSystem
  7. {
  8. public class CharacterAimAction : IAction
  9. {
  10. CharacterController character;
  11. Transform target;
  12. AimController aimController;
  13. GameObject aimTarget;
  14. // Constructor
  15. public CharacterAimAction(CharacterController character, Transform target)
  16. {
  17. this.character = character;
  18. this.target = target;
  19. }
  20. public void Start()
  21. {
  22. aimController = character.GetComponentInChildren<AimController>();
  23. if(aimController != null)
  24. {
  25. if(aimController.target != null)
  26. {
  27. aimTarget = aimController.target.gameObject;
  28. }
  29. else
  30. {
  31. aimTarget = new GameObject(character.unique_name + "_AimTarget");
  32. aimController.target = aimTarget.transform;
  33. }
  34. }
  35. else
  36. {
  37. End();
  38. }
  39. aimTarget.transform.position = new Vector3(target.position.x, target.position.y + 1.4f, target.position.z);
  40. }
  41. public void Update()
  42. {
  43. aimTarget.transform.position = new Vector3(target.position.x, target.position.y + 1.4f, target.position.z);
  44. }
  45. public void End()
  46. {
  47. if(aimController != null)
  48. {
  49. aimController.target = null;
  50. }
  51. target = null;
  52. GameObject.Destroy(aimTarget);
  53. }
  54. public bool IsDone()
  55. {
  56. if(target == null) return true;
  57. else return false;
  58. }
  59. }
  60. }