WallacesBirthrightProjectile.cs 2.8 KB

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