RingaboltsOathProjectile.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System.Collections;
  2. using UnityEngine;
  3. namespace UltimateNPCWeapons.Scripts
  4. {
  5. public class RingaboltsOathProjectile : MonoBehaviour
  6. {
  7. public float speed = 30;
  8. public float deathTimer = 1;
  9. private float projRange;
  10. private Transform t;
  11. private Renderer r;
  12. private GameObject atalanta;
  13. private int damage;
  14. private int anim = 0;
  15. private float tick = 0;
  16. private bool bursting;
  17. private bool reborn;
  18. private bool dying;
  19. private Vector3 dir;
  20. private void Awake()
  21. {
  22. t = transform;
  23. r = t.GetChild(0).GetComponent<Renderer>();
  24. atalanta = t.GetChild(1).gameObject;
  25. }
  26. private void Set(Package2 d)
  27. {
  28. damage = (int)d.damage;
  29. dir = new Vector3(d.dir.x, 0f, 0f);
  30. dir.Normalize();
  31. projRange = d.projRange;
  32. StartCoroutine(Die());
  33. }
  34. private IEnumerator Burst(Vector3 targ)
  35. {
  36. bursting = true;
  37. yield return new WaitForSeconds(0.1f);
  38. dir = targ - t.position;
  39. dir = new Vector3(dir.x, 0f, 0f);
  40. dir.Normalize();
  41. bursting = false;
  42. yield return new WaitForSeconds(0.4f);
  43. yield break;
  44. }
  45. private void Exile()
  46. {
  47. Network.RemoveRPCs(GetComponent<NetworkView>().viewID);
  48. Network.Destroy(gameObject);
  49. }
  50. [RPC]
  51. private void hide()
  52. {
  53. t.position = new Vector3(-500f, -500f, -500f);
  54. }
  55. private IEnumerator Die()
  56. {
  57. if (!dying)
  58. {
  59. dying = true;
  60. yield return new WaitForSeconds(deathTimer + projRange * 0.05f);
  61. if (!reborn)
  62. {
  63. hide();
  64. yield return new WaitForSeconds(5f);
  65. UnityEngine.Object.Destroy(gameObject);
  66. }
  67. else
  68. {
  69. reborn = false;
  70. dying = false;
  71. StartCoroutine(Die());
  72. }
  73. }
  74. yield break;
  75. }
  76. private IEnumerator DieNetwork(float w)
  77. {
  78. if (!dying)
  79. {
  80. dying = true;
  81. yield return new WaitForSeconds(deathTimer);
  82. hide();
  83. gameObject.GetComponent<NetworkView>().RPC("hide", RPCMode.All, new object[0]);
  84. yield return new WaitForSeconds(w);
  85. Exile();
  86. }
  87. yield break;
  88. }
  89. [RPC]
  90. private void DieN()
  91. {
  92. Network.RemoveRPCs(base.GetComponent<NetworkView>().viewID);
  93. Network.Destroy(base.gameObject);
  94. }
  95. private void Update()
  96. {
  97. tick += speed * Time.deltaTime;
  98. if (tick > 1.8f)
  99. {
  100. tick = 0;
  101. anim = (anim + 1) % 4;
  102. r.material.mainTextureOffset = new Vector2(0.25f * anim, 0f);
  103. }
  104. }
  105. private void Eye(int a)
  106. {
  107. if (!reborn)
  108. {
  109. damage += a;
  110. reborn = true;
  111. speed *= 1.2f;
  112. atalanta.SetActive(true);
  113. }
  114. }
  115. private void OnTriggerEnter(Collider c)
  116. {
  117. if (c.gameObject.layer == 9 || c.gameObject.layer == 28)
  118. {
  119. float[] array = new float[] { damage, t.position.x };
  120. if (Network.isServer)
  121. c.gameObject.SendMessage("TD", array);
  122. }
  123. }
  124. }
  125. }