SpaceJellyfishScript.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 
  2. using System;
  3. using System.Collections;
  4. using UnityEngine;
  5. namespace Subworlds.Scripts
  6. {
  7. class SpaceJellyfishScript : EnemyScript
  8. {
  9. private Vector3 dir;
  10. private bool attacking;
  11. private void Awake()
  12. {
  13. base.Initialize(130, 7, 80, new int[] { 25, 25, 52 }, 60);
  14. }
  15. private void Update()
  16. {
  17. if (Network.isServer)
  18. {
  19. if (!this.attacking)
  20. {
  21. this.r.velocity = new Vector3(0f, 0f, 0f);
  22. if (this.target)
  23. {
  24. if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 45f)
  25. {
  26. this.attacking = true;
  27. base.StartCoroutine(this.Attack());
  28. }
  29. else
  30. {
  31. this.target = null;
  32. this.r.velocity = new Vector3(0f, 0f, 0f);
  33. }
  34. }
  35. }
  36. }
  37. }
  38. private float speedVariant = 1;
  39. private IEnumerator Attack()
  40. {
  41. //gameObject.transform.GetChild(0).gameObject.GetComponent<Animation>().Play();
  42. yield return new WaitForSeconds(0.35f);
  43. speedVariant = (1 + UnityEngine.Random.Range(-10, 10) / 20f);
  44. yield return new WaitForSeconds(0.01f * UnityEngine.Random.Range(0, 25));
  45. for (int i = 0; i < 20; i++)
  46. {
  47. this.dir = this.target.transform.position - this.t.position;
  48. this.dir.Normalize();
  49. var prevRotation = gameObject.transform.GetChild(0).localEulerAngles.z + 90;
  50. var newRotation = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
  51. var diffAngle = (prevRotation - newRotation + 180) % 360 - 180;
  52. gameObject.transform.GetChild(0).localEulerAngles = new Vector3(0, 0, prevRotation - 90 - diffAngle / 6);
  53. yield return new WaitForSeconds(0.01f);
  54. }
  55. this.r.velocity = this.dir * (15f);
  56. yield return new WaitForSeconds(0.2f);
  57. for (int j = 0; j < 8; j++)
  58. {
  59. this.r.velocity = this.dir * (16f) * (1f / (j + 1)) * speedVariant;
  60. yield return new WaitForSeconds(0.5f);
  61. }
  62. this.r.velocity = new Vector3(0f, 0f, 0f);
  63. yield return new WaitForSeconds(0.2f);
  64. this.attacking = false;
  65. yield break;
  66. }
  67. }
  68. }