Advertisement
kadyr

Untitled

Sep 25th, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Turret : Enemy
  4. {
  5. [SerializeField]
  6. private Transform riffleStart;
  7.  
  8. [SerializeField]
  9. private GameObject bullet;
  10.  
  11. private float coolDown = 1f;
  12. private float timer;
  13. void Start()
  14. {
  15. player = GameObject.FindObjectOfType<PlayerMove>().gameObject;
  16. health = 50;
  17. damage = 15;
  18. }
  19.  
  20. protected override void Attack()
  21. {
  22. if (Vector3.Distance(transform.position, player.transform.position) < 20f)
  23. {
  24. transform.LookAt(player.transform.position);
  25. if (timer >= coolDown)
  26. {
  27. GameObject buf = Instantiate(bullet);
  28. buf.transform.position = riffleStart.transform.position;
  29. buf.transform.rotation = transform.rotation;
  30. buf.GetComponent<Bullet>().setDirection(transform.forward);
  31. timer = 0;
  32. }
  33. }
  34.  
  35. timer += Time.deltaTime;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement