GoldenShroomScript.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System.Collections;
  2. using UnityEngine;
  3. namespace MonsterNests.Scripts
  4. {
  5. class GoldenShroomScript : EnemyScript
  6. {
  7. private bool attacking;
  8. private Vector3 dir;
  9. private bool moving;
  10. private float spd;
  11. private bool shooting;
  12. private void Awake()
  13. {
  14. r = gameObject.GetComponent<Rigidbody>();
  15. t = transform;
  16. b = transform.GetChild(0).GetChild(0).gameObject;
  17. e = transform.GetChild(0).gameObject;
  18. networkR2 = gameObject.GetComponent<NetworkR2>();
  19. trig[0] = gameObject.transform.GetChild(1).gameObject;
  20. trig[1] = gameObject.transform.GetChild(2).gameObject;
  21. var drops = new int[] { 24, 53, 53 };
  22. Initialize(750, 8, 103, drops, 50);
  23. if (Network.isServer)
  24. {
  25. base.StartCoroutine(this.Bolt());
  26. }
  27. }
  28. [RPC]
  29. private void MakeFace()
  30. {
  31. base.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/roll"), Menuu.soundLevel / 10f);
  32. }
  33. private IEnumerator MF()
  34. {
  35. yield return new WaitForSeconds(0.8f);
  36. yield break;
  37. }
  38. private IEnumerator Bolt()
  39. {
  40. for (; ; )
  41. {
  42. if (this.target && Vector3.Distance(this.target.transform.position, this.t.position) < 20f)
  43. {
  44. this.shooting = true;
  45. base.GetComponent<NetworkView>().RPC("MakeFace", RPCMode.All, new object[0]);
  46. yield return new WaitForSeconds(0.2f);
  47. for (int i = 0; i < 3; i++)
  48. {
  49. GameObject p = (GameObject)Network.Instantiate(Resources.Load("proj/MonsterNests/goldenShroom"), this.t.position + new Vector3(0, i - 1, 0), Quaternion.identity, 0);
  50. p.SendMessage("EnemySet", this.target.transform.position, SendMessageOptions.DontRequireReceiver);
  51. }
  52. yield return new WaitForSeconds(0.5f);
  53. this.shooting = false;
  54. }
  55. yield return new WaitForSeconds(2f);
  56. }
  57. yield break;
  58. }
  59. private void Update()
  60. {
  61. if (Network.isServer)
  62. {
  63. if (this.target)
  64. {
  65. if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 80f)
  66. {
  67. if (!this.attacking)
  68. {
  69. this.attacking = true;
  70. base.StartCoroutine(this.Attack());
  71. }
  72. }
  73. else
  74. {
  75. this.target = null;
  76. this.r.velocity = new Vector3(0f, 0f, 0f);
  77. }
  78. }
  79. if (this.moving && !this.knocking && !this.shooting)
  80. {
  81. this.r.velocity = this.dir * this.spd;
  82. }
  83. }
  84. }
  85. private IEnumerator Attack()
  86. {
  87. if (this.target.transform.position.x > this.t.position.x)
  88. {
  89. this.e.transform.rotation = Quaternion.Euler(0f, 180f, 0f);
  90. }
  91. else
  92. {
  93. this.e.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
  94. }
  95. if (UnityEngine.Random.Range(0, 4) == 0)
  96. {
  97. this.spd = 3f;
  98. this.dir = this.t.position - this.target.transform.position;
  99. }
  100. else
  101. {
  102. this.spd = 12f;
  103. Vector3 a = new Vector3(this.target.transform.position.x, this.target.transform.position.y + (float)UnityEngine.Random.Range(-15, 15), 0f);
  104. this.dir = a - this.t.position;
  105. }
  106. this.dir.Normalize();
  107. this.moving = true;
  108. yield return new WaitForSeconds((float)UnityEngine.Random.Range(1, 3) * 0.2f);
  109. this.moving = false;
  110. yield return new WaitForSeconds(0.5f);
  111. this.attacking = false;
  112. yield break;
  113. }
  114. }
  115. }