BulletRotation.cs 880 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using UnityEngine;
  3. public class BulletRotation : 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 Start()
  14. {
  15. }
  16. private void Update()
  17. {
  18. if (this.start)
  19. {
  20. this.CalculateAngle();
  21. }
  22. if (this.isOnGround)
  23. {
  24. UnityEngine.Object.Destroy(base.gameObject);
  25. }
  26. }
  27. private void CalculateAngle()
  28. {
  29. this.speedAngle = Vector2.Angle(base.GetComponent<Rigidbody2D>().velocity, Vector2.up) * (float)this.dir;
  30. base.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, this.speedAngle));
  31. }
  32. public void StartCalculate(int _dir)
  33. {
  34. this.dir = _dir;
  35. this.start = true;
  36. }
  37. private float speedAngle;
  38. private bool start;
  39. private int dir;
  40. }