AttackDroidScript.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. }
  17. private void Update()
  18. {
  19. if (Network.isServer)
  20. {
  21. if (!this.attacking)
  22. {
  23. this.r.velocity = new Vector3(0f, 0f, 0f);
  24. if (this.target)
  25. {
  26. if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 45f)
  27. {
  28. this.attacking = true;
  29. base.StartCoroutine(this.Attack());
  30. }
  31. else
  32. {
  33. this.target = null;
  34. this.r.velocity = new Vector3(0f, 0f, 0f);
  35. }
  36. }
  37. }
  38. }
  39. }
  40. private IEnumerator Attack()
  41. {
  42. gameObject.transform.GetChild(0).gameObject.GetComponent<Animation>().Play();
  43. yield return new WaitForSeconds(0.55f);
  44. this.dir = this.target.transform.position - this.t.position;
  45. this.dir.Normalize();
  46. yield return new WaitForSeconds(0.05f);
  47. this.r.velocity = this.dir * (30f);
  48. yield return new WaitForSeconds(1.1f);
  49. this.r.velocity = new Vector3(0f, 0f, 0f);
  50. this.attacking = false;
  51. yield break;
  52. }
  53. }
  54. }