NormalCrystal.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using UnityEngine;
  3. public class NormalCrystal : BaseBehaviour
  4. {
  5. private bool isOnGround
  6. {
  7. get
  8. {
  9. RaycastHit2D hit = Physics2D.Raycast(base.transform.position, -Vector2.up, 0.18f, LayerManager.GroundMask);
  10. return hit;
  11. }
  12. }
  13. private void OnEnable()
  14. {
  15. this.canUse = false;
  16. base.GetComponent<Rigidbody2D>().velocity = new Vector2(UnityEngine.Random.Range(-this.speed.x, this.speed.x), UnityEngine.Random.Range(3f, this.speed.y));
  17. }
  18. private void Update()
  19. {
  20. if (this.isOnGround)
  21. {
  22. if (base.GetComponent<Rigidbody2D>().velocity.magnitude > 0.1f)
  23. {
  24. base.transform.Rotate(Vector3.back, (float)this.rotation * Time.deltaTime);
  25. base.GetComponent<Rigidbody2D>().velocity = new Vector2(base.GetComponent<Rigidbody2D>().velocity.x * (1f - this.friction), -base.GetComponent<Rigidbody2D>().velocity.y * this.bounce);
  26. }
  27. else
  28. {
  29. this.canUse = true;
  30. base.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
  31. }
  32. }
  33. else
  34. {
  35. base.transform.Rotate(Vector3.back, (float)this.rotation * Time.deltaTime);
  36. base.GetComponent<Rigidbody2D>().AddForce(this.gravity);
  37. }
  38. }
  39. private void OnTriggerStay2D(Collider2D other)
  40. {
  41. if (other.name == "PlayerHurtBox" && this.canUse)
  42. {
  43. R.Effect.Generate(97, null, base.transform.position, default(Vector3), default(Vector3), true);
  44. EffectController.TerminateEffect(base.gameObject);
  45. }
  46. }
  47. [SerializeField]
  48. private Vector2 speed;
  49. [SerializeField]
  50. private Vector2 gravity;
  51. [SerializeField]
  52. private int rotation;
  53. [SerializeField]
  54. private float friction = 0.1f;
  55. [SerializeField]
  56. private float bounce = 1f;
  57. private bool canUse;
  58. }