AttackDroidScript.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 
  2. using System;
  3. using System.Collections;
  4. using UnityEngine;
  5. namespace Subworlds.Scripts
  6. {
  7. class AttackDroidScript : EnemyScript
  8. {
  9. private Vector3 dir;
  10. private bool attacking;
  11. private void Awake()
  12. {
  13. base.trig[0] = gameObject.transform.GetChild(1).gameObject;
  14. base.trig[1] = gameObject.transform.GetChild(2).gameObject;
  15. base.Initialize(100, 5, 70, new int[] { 3, 3, 57 }, 60);
  16. var network = gameObject.GetComponent<NetworkEnemyBasic>();
  17. network.isPirate = true;
  18. }
  19. private void Update()
  20. {
  21. if (Network.isServer)
  22. {
  23. if (!this.attacking)
  24. {
  25. this.r.velocity = new Vector3(0f, 0f, 0f);
  26. if (this.target)
  27. {
  28. if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 45f)
  29. {
  30. this.attacking = true;
  31. base.StartCoroutine(this.Attack());
  32. }
  33. else
  34. {
  35. this.target = null;
  36. this.r.velocity = new Vector3(0f, 0f, 0f);
  37. }
  38. }
  39. }
  40. }
  41. }
  42. private IEnumerator Attack()
  43. {
  44. gameObject.transform.GetChild(0).gameObject.GetComponent<Animation>().Play();
  45. yield return new WaitForSeconds(0.55f);
  46. this.dir = this.target.transform.position - this.t.position;
  47. this.dir.Normalize();
  48. yield return new WaitForSeconds(0.05f);
  49. this.r.velocity = this.dir * (30f);
  50. yield return new WaitForSeconds(1.1f);
  51. this.r.velocity = new Vector3(0f, 0f, 0f);
  52. this.attacking = false;
  53. yield break;
  54. }
  55. }
  56. }