CharacterHandWeaponAttackAction.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using KairoEngine.Core;
  6. using KairoEngine.Inventory;
  7. using KairoEngine.SFX;
  8. namespace KairoEngine.CharacterSystem
  9. {
  10. /// <summary>
  11. /// Action to move a character in a certain direction and speed.
  12. /// </summary>
  13. public class CharacterHandWeaponAttackAction : IAction
  14. {
  15. CharacterController character; // Reference to the character that will move
  16. Vector3 targetPosition;
  17. bool done = false;
  18. GameObject particleSystem;
  19. HandWeapon handWeaponScript;
  20. // Constructor
  21. public CharacterHandWeaponAttackAction(CharacterController character, Vector3 targetPosition)
  22. {
  23. this.character = character;
  24. this.targetPosition = targetPosition;
  25. }
  26. public void Start()
  27. {
  28. character.animator.SetTrigger("Attack");
  29. character.rightHand.GetComponentInChildren<DamageEmitter>().enabled = true;
  30. GenericEvents.StartListening(character.unique_name + "-AnimationMeleeEnd", End);
  31. ItemRef itemRef = character.GetEquipedItem();
  32. ItemBaseHandWeapon handWeapon = (ItemBaseHandWeapon)itemRef.item;
  33. SoundController.EmmitSound(handWeapon.attackSound, targetPosition);
  34. GameObject weapon = character.GetEquipedGameObject();
  35. particleSystem = weapon.GetComponent<HandWeapon>().particleSystemGroup;
  36. particleSystem.SetActive(true);
  37. ParticleSystem[] systems = particleSystem.GetComponentsInChildren<ParticleSystem>();
  38. foreach (var system in systems)
  39. {
  40. system.loop = true;
  41. system.Play();
  42. }
  43. handWeaponScript = weapon.GetComponent<HandWeapon>();
  44. if(handWeaponScript != null) handWeaponScript.damageTrigger.enabled = true;
  45. }
  46. public void Update() { }
  47. public void End()
  48. {
  49. done = true;
  50. GenericEvents.StopListening(character.unique_name + "-AnimationMeleeEnd", End);
  51. character.rightHand.GetComponentInChildren<DamageEmitter>().enabled = false;
  52. ParticleSystem[] systems = particleSystem.GetComponentsInChildren<ParticleSystem>();
  53. foreach (var system in systems)
  54. {
  55. system.loop = false;
  56. }
  57. //if(handWeaponScript != null) handWeaponScript.damageTrigger.enabled = false;
  58. }
  59. public bool IsDone()
  60. {
  61. return done;
  62. }
  63. }
  64. }