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;
- [SerializeField]
- private GameObject weaponGameObject;
- private Animator animator; // Создаем переменную аниматора 55555
- void Start()
- {
- player = FindObjectOfType<PlayerController>().gameObject; //Находим игрока
- animator = GetComponent<Animator>(); // получаем переменную из компонента 55555
- }
- public void Death()
- {
- animator.SetTrigger("DeathTrigger");
- area = 0;
- Destroy(weaponGameObject);
- }
- // 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