WallacesBirthrightProjectile.cs 2.8 KB

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