Advertisement
kadyr

Untitled

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