Advertisement
kadyr

Untitled

Oct 24th, 2021
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Turret : MonoBehaviour
  6. {
  7. [SerializeField] GameObject player;
  8. [SerializeField] GameObject bullet;
  9. [SerializeField] GameObject rifleStart;
  10.  
  11. float area = 100;
  12.  
  13. float timer = 0;
  14. float cooldown = 1;
  15.  
  16. // Start is called before the first frame update
  17. void Start()
  18. {
  19. player = FindObjectOfType<PlayerController>().gameObject; //Находим игрока
  20. }
  21.  
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. if (Vector3.Distance(transform.position, player.transform.position) < area)
  26. {
  27. transform.LookAt(player.transform);
  28. timer += Time.deltaTime;
  29. if (timer > cooldown)
  30. {
  31. timer = 0;
  32. GameObject buf = Instantiate(bullet);
  33. buf.transform.position = rifleStart.transform.position;
  34. buf.GetComponent<Bullet>().SetDirection(transform.forward);
  35. buf.transform.rotation = transform.rotation;
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement