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
- {
- public GameObject playerObject;
- public Transform riffleStart;
- public GameObject bullet;
- [SerializeField] float area = 20f;
- float timer = 0;
- float coolDown = 2f;
- void Start()
- {
- playerObject = GameObject.FindObjectOfType<PlayerController>().gameObject;
- }
- void Update()
- {
- if (Vector3.Distance(transform.position, playerObject.transform.position) < area)
- {
- transform.LookAt(playerObject.transform.position);
- timer += Time.deltaTime;
- if (timer > coolDown)
- {
- GameObject bul = Instantiate(bullet, riffleStart.transform.position, riffleStart.transform.rotation);
- bul.GetComponent<Bullet>().SetDirection(transform.forward);
- timer = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement