SalvoBullet.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using UnityEngine;
  3. public class SalvoBullet : BaseBehaviour
  4. {
  5. private bool isOnGround
  6. {
  7. get
  8. {
  9. RaycastHit2D hit = Physics2D.Raycast(base.transform.position, -Vector2.up, 0.36f, LayerManager.GroundMask);
  10. return hit;
  11. }
  12. }
  13. private void OnEnable()
  14. {
  15. this.isUseExplosion = false;
  16. }
  17. private void Update()
  18. {
  19. base.GetComponent<Rigidbody2D>().velocity -= new Vector2(base.GetComponent<Rigidbody2D>().velocity.x * Time.deltaTime * 1.2f, 0f);
  20. if (this.start)
  21. {
  22. this.CalculateAngle();
  23. }
  24. if (this.isOnGround)
  25. {
  26. if (!this.isUseExplosion)
  27. {
  28. this.isUseExplosion = true;
  29. R.Effect.Generate(75, base.transform, new Vector3(0f, 0.5f, 0f), default(Vector3), default(Vector3), true).GetComponent<SalvoBulletExplosion>().SetDamage(this.damage);
  30. }
  31. this.start = false;
  32. EffectController.TerminateEffect(base.gameObject);
  33. }
  34. }
  35. private void CalculateAngle()
  36. {
  37. this.speedAngle = Vector2.Angle(base.GetComponent<Rigidbody2D>().velocity, Vector2.up) * (float)this.dir;
  38. base.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, this.speedAngle));
  39. }
  40. public void StartCalculate(int _dir)
  41. {
  42. this.dir = _dir;
  43. this.start = true;
  44. }
  45. public void SetDamage(int _damage)
  46. {
  47. this.damage = _damage;
  48. }
  49. private float speedAngle;
  50. private bool start;
  51. private int dir;
  52. private Transform player;
  53. public int damage;
  54. private bool isUseExplosion;
  55. }