CharacterUnarmedAttackAction.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using KairoEngine.Core;
  6. namespace KairoEngine.CharacterSystem
  7. {
  8. /// <summary>
  9. /// Action to move a character in a certain direction and speed.
  10. /// </summary>
  11. public class CharacterUnarmedAttackAction : IAction
  12. {
  13. CharacterController character; // Reference to the character that will move
  14. Vector3 targetPosition;
  15. bool done = false;
  16. // Constructor
  17. public CharacterUnarmedAttackAction(CharacterController character, Vector3 targetPosition)
  18. {
  19. this.character = character;
  20. this.targetPosition = targetPosition;
  21. }
  22. public void Start()
  23. {
  24. if(Random.Range(0, 2) == 0)
  25. {
  26. character.animator.SetTrigger("AttackL");
  27. character.rightUnarmedObject.SetActive(true);
  28. }
  29. else
  30. {
  31. character.animator.SetTrigger("AttackR");
  32. character.leftUnarmedObject.SetActive(true);
  33. }
  34. GenericEvents.StartListening(character.unique_name + "-AnimationMeleeEnd", End);
  35. }
  36. public void Update() { }
  37. public void End()
  38. {
  39. done = true;
  40. GenericEvents.StopListening(character.unique_name + "-AnimationMeleeEnd", End);
  41. character.rightUnarmedObject.SetActive(false);
  42. character.leftUnarmedObject.SetActive(false);
  43. }
  44. public bool IsDone()
  45. {
  46. return done;
  47. }
  48. }
  49. }