AttackDroidScript.cs 1.3 KB

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