Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class AtackTower : MonoBehaviour
  4. {
  5.     public GameObject bullet;
  6.     public float speedbullet;
  7.     float hpcreep;
  8.     public float fireRate = 1.5f;
  9.     private float nextFire = 0.0f;
  10.     Transform plLast;
  11.     public GameObject target;
  12.  
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.     }
  17.  
  18.     // Update is called once per frame
  19.     void Update()
  20.     {
  21.        
  22.     }
  23.  
  24.     void OnTriggerStay(Collider other) // ПОПРОБОВАТЬ ОПРОКИНУТЬ ВСЁ ЭТО ДЕРЬМО ЕРЕЗ OnriggerStay
  25.     {
  26.          if (other.tag == "creep")
  27.          {
  28.             hpcreep = other.gameObject.GetComponent<HPcreep>().hp;
  29.             if (hpcreep > 0)
  30.             {
  31.                 if (Time.time > nextFire)
  32.                 {
  33.                     Debug.unityLogger.Log("hpcreep", hpcreep);
  34.                     nextFire = Time.time + fireRate;
  35.                     //задаётся вектор создания пули, то есть точка её появления, и создаётся сама пуля
  36.                     Vector3 bulletpos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1.5f);
  37.                     GameObject bull = Instantiate(bullet, bulletpos, transform.rotation);                    
  38.                         //создаётся переменная типа мувбулет, и присваевается к ней компонентк мувболет; к переменной pl типа трансформ присваивается вектор крипа в текущем кадре
  39.                         // и передаётся в класс Movebullet, в метод SetTarget.
  40.                         Movebullet mb = bull.GetComponent<Movebullet>();
  41.                         GameObject pl = other.gameObject;
  42.                        
  43.                         /*if (pl != null)
  44.                         {
  45.                             //plLast = pl;
  46.                             //mb.SetTarget(pl);
  47.                             //Debug.unityLogger.Log("pl=", pl.position.x);
  48.                             Debug.unityLogger.Log("plast=", plLast.position.x);
  49.                          }
  50.                         else
  51.                         {                            
  52.                             mb.SetTarget(plLast);
  53.                         }                 */  
  54.                 }
  55.                
  56.             }        
  57.            
  58.          }
  59.  
  60.     }
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement