Advertisement
kadyr

Untitled

Oct 31st, 2021
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 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]
  8.     GameObject player;
  9.  
  10.     [SerializeField]
  11.     GameObject bullet;
  12.  
  13.     [SerializeField]
  14.     GameObject rifleStart;
  15.  
  16.     [SerializeField]
  17.     float area = 100;
  18.  
  19.     float timer = 0;
  20.     float cooldown = 1;
  21.  
  22.     private Animator animator; // Создаем переменную аниматора 55555
  23.  
  24.     void Start()
  25.     {
  26.         player = FindObjectOfType<PlayerController>().gameObject; //Находим игрока
  27.         animator = GetComponent<Animator>(); // получаем переменную из компонента 55555
  28.     }
  29.  
  30.     public void Death() //55555  
  31.     {//55555  
  32.         animator.SetTrigger("DeathTrigger");//55555  
  33.         area = 0;
  34.     }//55555  
  35.  
  36.     // Update is called once per frame
  37.     void Update()
  38.     {
  39.         if (Vector3.Distance(transform.position, player.transform.position) < area)
  40.         {
  41.             transform.LookAt(player.transform);
  42.             timer += Time.deltaTime;
  43.             if (timer > cooldown)
  44.             {
  45.                 timer = 0;
  46.                 GameObject buf = Instantiate(bullet, rifleStart.transform.position, transform.rotation);
  47.                 buf.GetComponent<Bullet>().SetDirection(transform.forward);
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement