Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `public class Attack_Tower_1 : MonoBehaviour
- {
- public List<GameObject> enemys;//список враго(тут всё правильно)
- Vector2 spawnpoint;
- float distance;
- GameObject tower;
- //public Shell shell_1;
- //public Shell shell_2;
- [SerializeField]
- private GameObject[] shells = new GameObject[1];
- GameObject image;
- void Start()
- {
- spawnpoint = transform.position;
- image = GameObject.Find("Image");
- /*if(image!= null)
- {
- image.SetActive(false);
- }*/
- tower = gameObject;
- enemys = GetComponent<Towers>().enemys;
- InvokeRepeating("Attack", 1f, 0.1f);
- }
- void Attack()
- {
- if (enemys.Count > 0 /*&& tower.GetComponent<Towers>().TimerAttack <= 0f*/)
- {
- // image.SetActive(true);
- transform.Rotate(new Vector3(0f, 0f, 90f));
- //distance = Vector3.Distance(enemys[0].transform.position, transform.position);
- for (int i = 0; i < enemys.Count; i++)
- {
- if (enemys.Count > 0 && enemys[i] != null)
- {
- Instantiate(shells[0], spawnpoint, transform.rotation);
- Instantiate(shells[1], spawnpoint, transform.rotation);
- float distance = Vector2.Distance(enemys[i].transform.position, transform.position);
- //if (distance <= 5f)
- shells[0].transform.LookAt(enemys[i].transform);
- transform.position = Vector3.Lerp(shells[0].transform.position, enemys[i].transform.position,
- (Random.Range(6F, 10F) * distance) * Time.fixedDeltaTime);
- shells[1].transform.LookAt(enemys[i].transform);
- transform.position = Vector3.Lerp(shells[1].transform.position, enemys[i].transform.position,
- (Random.Range(6F, 10F) * distance) * Time.fixedDeltaTime);
- }
- }
- }
- }
- }`
Add Comment
Please, Sign In to add comment