Писал код что бы башня стреляла и тут вот такое:
вот код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tower : MonoBehaviour
{
public Transform shootElement;
public Transform LookAtObj;
public float dmg = 5;
public float shootSpeed;
public GameObject bullet;
public Transform target;
public float shootDelay;
bool IsShoot;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (target)
LookAtObj.transform.LookAt(target);
if (!IsShoot)
StartCoroutine(shoot());
}
IEnumerator shoot()
{
IsShoot = true;
yield return new WaitForSeconds(shootDelay);
GameObject b = GameObject.Instantiate(bullet, shootElement.position, Quaternion.identity) as GameObject;
b.GetComponent<bulletTower>().target = target;
IsShoot = false;
}
}