Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Turret : MonoBehaviour
- {
- [SerializeField] GameObject player;
- [SerializeField] GameObject bullet;
- [SerializeField] GameObject rifleStart;
- [SerializeField]
- float area = 100;
- float timer = 0;
- float cooldown = 1;
- // Start is called before the first frame update
- void Start()
- {
- player = FindObjectOfType<PlayerController>().gameObject; //Находим игрока
- }
- // Update is called once per frame
- void Update()
- {
- if (Vector3.Distance(transform.position, player.transform.position) < area)
- {
- transform.LookAt(player.transform);
- timer += Time.deltaTime;
- if (timer > cooldown)
- {
- timer = 0;
- GameObject buf = Instantiate(bullet,rifleStart.transform.position,transform.rotation);
- buf.GetComponent<Bullet>().SetDirection(transform.forward);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement