EnergyBall.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class EnergyBall : BaseBehaviour
  5. {
  6. private float deltaTime
  7. {
  8. get
  9. {
  10. return Time.time - this.startTime;
  11. }
  12. }
  13. private void OnEnable()
  14. {
  15. this.startTime = Time.time;
  16. this.player = R.Player.Transform;
  17. base.transform.Find("Tail").gameObject.SetActive(true);
  18. base.transform.Find("Flash").gameObject.SetActive(true);
  19. Vector2 vector = new Vector2(((this.player.GetComponent<Collider2D>().bounds.center - base.transform.position).x <= 0f) ? UnityEngine.Random.Range(0f, 1f) : UnityEngine.Random.Range(-1f, 0f), UnityEngine.Random.Range(-1f, 1f));
  20. this.randomDir = vector.normalized * 5f;
  21. base.GetComponent<Rigidbody2D>().velocity = this.randomDir;
  22. base.gameObject.GetComponent<Animator>().Play("EnergyBallFade");
  23. base.transform.Find("Tail").localPosition = Vector3.zero;
  24. Light component = this.light.GetComponent<Light>();
  25. component.intensity = 3f;
  26. base.StartCoroutine(this.UseBall());
  27. }
  28. private void Update()
  29. {
  30. }
  31. private IEnumerator UseBall()
  32. {
  33. while (this.deltaTime <= this.waitTime)
  34. {
  35. base.GetComponent<Rigidbody2D>().AddForce(new Vector2(-base.GetComponent<Rigidbody2D>().velocity.y, base.GetComponent<Rigidbody2D>().velocity.x) * 6f);
  36. if (Vector2.Angle(base.GetComponent<Rigidbody2D>().velocity, base.transform.position - this.player.position) > 160f && this.deltaTime <= this.waitTime)
  37. {
  38. break;
  39. }
  40. yield return new WaitForFixedUpdate();
  41. }
  42. base.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 0f));
  43. while (this.isMove)
  44. {
  45. base.transform.position = Vector3.MoveTowards(base.transform.position, this.player.position + this.repairPosition, 0.02f * this.speed * this.deltaTime);
  46. yield return new WaitForFixedUpdate();
  47. if (Vector3.Distance(base.transform.position, this.player.position + this.repairPosition) < 0.4f)
  48. {
  49. this.EnergyBallFunction(this.energyType);
  50. base.transform.Find("Tail").gameObject.SetActive(false);
  51. base.gameObject.GetComponent<Animator>().Play("EnergyBallCollision");
  52. base.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, 0f);
  53. base.transform.Find("Flash").gameObject.SetActive(false);
  54. base.StartCoroutine(this.player.GetComponent<ChangeSpineColor>().EnergyBallColorChange());
  55. base.StartCoroutine(this.FadeInLight());
  56. break;
  57. }
  58. }
  59. yield break;
  60. }
  61. private void EnergyBallFunction(EnergyBall.EnergyBallType energyType)
  62. {
  63. if (energyType != EnergyBall.EnergyBallType.Armor)
  64. {
  65. }
  66. }
  67. private IEnumerator FadeInLight()
  68. {
  69. Light i = this.light.GetComponent<Light>();
  70. while (i.range < 6f)
  71. {
  72. i.range += 0.2f;
  73. yield return new WaitForSeconds(0.04f);
  74. }
  75. i.range = 4f;
  76. i.intensity = 0f;
  77. yield break;
  78. }
  79. [SerializeField]
  80. private bool isMove = true;
  81. [SerializeField]
  82. private float speed = 1f;
  83. [SerializeField]
  84. private float minDistance = 0.1f;
  85. [SerializeField]
  86. private float MaxDistance = 2.5f;
  87. [SerializeField]
  88. private EnergyBall.EnergyBallType energyType;
  89. [SerializeField]
  90. private int energyValue = 10;
  91. [SerializeField]
  92. private float waitTime;
  93. [SerializeField]
  94. private Transform light;
  95. private float startTime;
  96. private Transform player;
  97. private Vector3 repairPosition = new Vector3(0f, 1.2f, -0.1f);
  98. private Vector2 randomDir;
  99. public enum EnergyBallType
  100. {
  101. Armor = 1,
  102. Skill
  103. }
  104. }