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; [SerializeField] private Animator enemyAnimator; [SerializeField] private int health = 100; void Start() { playerObject = GameObject.FindObjectOfType().gameObject; enemyAnimator = GetComponent(); } public void ChangeHealth(int hp) { health += hp; if (health <= 0) Dead(); } public void Dead() { enemyAnimator.SetTrigger("deathTrigger"); area = -1; } 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().SetDirection(transform.forward); timer = 0; } } } }