BrokenTurretScript.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections;
  2. using UnityEngine;
  3. namespace Subworlds.Scripts
  4. {
  5. class BrokenTurretScript : EnemyScript
  6. {
  7. private Vector3 dir;
  8. private bool attacking;
  9. private void Awake()
  10. {
  11. base.trig[0] = gameObject.transform.GetChild(1).gameObject;
  12. base.trig[1] = gameObject.transform.GetChild(2).gameObject;
  13. base.Initialize(130, 7, 80, new int[] { 25, 25, 52 }, 60);
  14. }
  15. private void Update()
  16. {
  17. if (Network.isServer)
  18. {
  19. if (!this.attacking)
  20. {
  21. if (this.target)
  22. {
  23. if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 45f)
  24. {
  25. this.attacking = true;
  26. base.StartCoroutine(this.Attack());
  27. }
  28. else
  29. {
  30. this.target = null;
  31. }
  32. }
  33. }
  34. }
  35. }
  36. private int z = 0;
  37. private IEnumerator Seach(int count)
  38. {
  39. for (int i = 0; i < count; i++)
  40. {
  41. this.dir = this.target.transform.position - this.t.position;
  42. this.dir.Normalize();
  43. var newRotation = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
  44. var diffAngle = (z - newRotation + 180) % 360 - 180;
  45. z = (int)(z - diffAngle / 6f);
  46. z = (z + 360) % 360;
  47. gameObject.transform.GetChild(0).GetChild(0).GetChild(0).localEulerAngles = new Vector3(0, ((z + 360 - 90) % 360) > 180 ? 0 : 180, ((z + 360 - 90) % 360) > 180 ? z : 180 - z);
  48. yield return new WaitForSeconds(0.01f);
  49. }
  50. }
  51. private IEnumerator Attack()
  52. {
  53. yield return Seach(100 + Random.Range(0, 30));
  54. for (int i = 0; i < 3; i++)
  55. {
  56. var pos = this.target.transform.position;
  57. yield return new WaitForSeconds(0.125f);
  58. var p = (GameObject)Network.Instantiate(Resources.Load("proj/pirateproj"), this.t.position, Quaternion.identity, 0);
  59. p.SendMessage("EnemySet", pos, SendMessageOptions.DontRequireReceiver);
  60. yield return new WaitForSeconds(0.125f);
  61. yield return Seach(10);
  62. }
  63. this.attacking = false;
  64. yield break;
  65. }
  66. }
  67. }