RingaboltsOathProjectile.cs 3.0 KB

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