CharacterShootAction.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Core;
  5. using KairoEngine.Inventory;
  6. namespace KairoEngine.CharacterSystem
  7. {
  8. public class CharacterShootAction : IAction
  9. {
  10. CharacterController character;
  11. Firearm firearm;
  12. bool isDone = false;
  13. // Constructor
  14. public CharacterShootAction(CharacterController character)
  15. {
  16. this.character = character;
  17. }
  18. public void Start()
  19. {
  20. if(character.HasEquipedItem() == false) return;
  21. if(character.GetEquipedItem().item.category != ItemType.firearm) return;
  22. firearm = character.GetEquipedGameObject().GetComponent<Firearm>();
  23. ItemBaseFirearm weaponItem = (ItemBaseFirearm)firearm.itemFirearmRef.item;
  24. if(weaponItem.firearmType == FirearmType.pistol) character.animator.SetBool("Pistol", true);
  25. else character.animator.SetBool("Pistol", false);
  26. if(firearm.isReady)
  27. {
  28. firearm.Fire();
  29. if(firearm.itemFirearmRef.ammo > 0) character.animator.SetTrigger("Attack");
  30. isDone = true;
  31. }
  32. }
  33. public void Update()
  34. {
  35. if(firearm.isReady && !isDone)
  36. {
  37. firearm.Fire();
  38. isDone = true;
  39. }
  40. }
  41. public void End() { }
  42. public bool IsDone()
  43. {
  44. return isDone;
  45. }
  46. }
  47. }