PolliwogShot.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Sirenix.OdinInspector;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class PolliwogShot : SpecialSkills
  6. {
  7. [Header("òòò½Ô¤ÖÆÌå")]
  8. public GameObject fishPrefab;
  9. public Vector2 groupCenter { get; set; }
  10. private float lastUpdateCenterTime;
  11. private Vector2 groupVelocity;
  12. private float lastUpdateVelocityTime;
  13. public int num;
  14. public override void Attack()
  15. {
  16. for (int i = 0; i < num; i++)
  17. {
  18. if(PolliwogManager.GetInstance().IsFull()) continue;
  19. PoolManager.InstantiateAsync("Prefab/Enemy/Enemy_Polliwog", transform.position + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0));
  20. }
  21. }
  22. public void Attack(int num, Vector3 pos)
  23. {
  24. for (int i = 0; i < num; i++)
  25. {
  26. if (PolliwogManager.GetInstance().IsFull()) continue;
  27. PoolManager.InstantiateAsync("Prefab/Enemy/Enemy_Polliwog", pos, new Quaternion(0, 0, 0, 0), null, obj =>
  28. {
  29. Polliwog pol = obj.GetComponent<Polliwog>();
  30. });
  31. }
  32. }
  33. public Vector3 UpdateGroupCenter()
  34. {
  35. if (Time.time - lastUpdateCenterTime < 0.1f) return groupCenter;
  36. lastUpdateCenterTime = Time.time;
  37. groupCenter = Vector2.zero;
  38. foreach (Polliwog pol in PolliwogManager.GetInstance().list)
  39. {
  40. groupCenter += (Vector2)transform.position;
  41. }
  42. groupCenter /= PolliwogManager.GetInstance().list.Count;
  43. return groupCenter;
  44. }
  45. public Vector2 UpdateGroupVelocity()
  46. {
  47. if (Time.time - lastUpdateVelocityTime < 0.1f) return groupVelocity;
  48. lastUpdateVelocityTime = Time.time;
  49. groupVelocity = Vector2.zero;
  50. foreach (Polliwog pol in PolliwogManager.GetInstance().list)
  51. {
  52. groupVelocity += pol.currentVelocity;
  53. }
  54. groupVelocity /= PolliwogManager.GetInstance().list.Count;
  55. return groupVelocity;
  56. }
  57. }