ChainShoot.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Sirenix.OdinInspector;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class ChainShoot : SpecialSkills
  6. {
  7. [LabelText("弓箭预制体")] public GameObject arrow;
  8. [LabelText("连击间隔")] public float attackInterval;
  9. [LabelText("连击次数")] public float attackNum;
  10. public int num;
  11. public float time;
  12. public bool startAttack;
  13. private Vector3 attackDir;
  14. public override void Attack()
  15. {
  16. base.Attack();
  17. time = 0;
  18. num = 0;
  19. startAttack = true;
  20. }
  21. public void Update()
  22. {
  23. if (startAttack)
  24. {
  25. time += Time.deltaTime;
  26. if(time > attackInterval)
  27. {
  28. time = 0;
  29. if(owner.targetCharacter == null)
  30. {
  31. startAttack = false;
  32. owner.ChangeState(CharacterState.Idle);
  33. return;
  34. }
  35. attackDir = (owner.targetCharacter.beSearchTrigger.transform.position - transform.position).normalized;
  36. Shoot();
  37. num ++;
  38. if(num >= attackNum)
  39. {
  40. startAttack = false;
  41. }
  42. }
  43. }
  44. }
  45. public void Shoot()
  46. {
  47. Bullet bullet = PoolManager.Instantiate(arrow).GetComponent<Bullet>();
  48. AttackController.AttackMethod attackMethod = owner.attackController.attackMethod_march[0];
  49. bullet.BeShoot(owner, transform.position, attackDir,true,target:owner.targetCharacter);
  50. }
  51. }