Advertisement
kadyr

Untitled

Sep 12th, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. public class SniperEnemy : Enemy
  5. {
  6. [SerializeField]
  7. GameObject bullet;
  8.  
  9. [SerializeField]
  10. GameObject rifleStart;
  11.  
  12. [SerializeField]
  13. float cooldown = 1f;
  14.  
  15. float timer = 0;
  16. float area = 25;
  17.  
  18. private enum SniperState
  19. {
  20. Wait,
  21. Prepare,
  22. Shoot
  23. }
  24.  
  25. private SniperState _currentState = SniperState.Wait;
  26.  
  27. void Start() { }
  28.  
  29. public override void Move()//михаил
  30. {
  31. if (_currentState == SniperState.Wait)
  32. {
  33. GetComponent<CharacterController>().Move(transform.forward * Time.deltaTime * 2f);
  34. timer += Time.deltaTime;
  35. if (timer > 10)
  36. {
  37. transform.Rotate(new Vector3(0,90,0));
  38. timer = 0;
  39. }
  40. }
  41. }
  42.  
  43. public override void Attack()
  44. {
  45. switch (_currentState)
  46. {
  47. case SniperState.Wait: // Эли
  48. if (Vector3.Distance(transform.position, player.transform.position) <= area)
  49. {
  50. _currentState = SniperState.Prepare;
  51. timer = 0;
  52. }
  53. break;
  54. case SniperState.Prepare: //Салимхан
  55. timer += Time.deltaTime;
  56. transform.LookAt(player.transform.position);
  57. if (timer > cooldown)
  58. {
  59. _currentState = SniperState.Shoot;
  60. //прицеливание
  61. }
  62. break;
  63. case SniperState.Shoot: //Кузьма
  64. timer = 0;
  65. GameObject buf = Instantiate(bullet);
  66. buf.transform.position = rifleStart.transform.position;
  67. buf.transform.rotation = transform.rotation;
  68. buf.GetComponent<Bullet>().setDirection(transform.forward);
  69. _currentState = SniperState.Wait;
  70. break;
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement