Guest User

Untitled

a guest
Jan 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. `public class Attack_Tower_1 : MonoBehaviour
  2. {
  3. public List<GameObject> enemys;//список враго(тут всё правильно)
  4. Vector2 spawnpoint;
  5. float distance;
  6. GameObject tower;
  7. //public Shell shell_1;
  8. //public Shell shell_2;
  9. [SerializeField]
  10. private GameObject[] shells = new GameObject[1];
  11. GameObject image;
  12. void Start()
  13. {
  14. spawnpoint = transform.position;
  15. image = GameObject.Find("Image");
  16. /*if(image!= null)
  17. {
  18. image.SetActive(false);
  19. }*/
  20. tower = gameObject;
  21. enemys = GetComponent<Towers>().enemys;
  22. InvokeRepeating("Attack", 1f, 0.1f);
  23. }
  24. void Attack()
  25. {
  26. if (enemys.Count > 0 /*&& tower.GetComponent<Towers>().TimerAttack <= 0f*/)
  27. {
  28. // image.SetActive(true);
  29. transform.Rotate(new Vector3(0f, 0f, 90f));
  30. //distance = Vector3.Distance(enemys[0].transform.position, transform.position);
  31.  
  32. for (int i = 0; i < enemys.Count; i++)
  33. {
  34. if (enemys.Count > 0 && enemys[i] != null)
  35. {
  36. Instantiate(shells[0], spawnpoint, transform.rotation);
  37. Instantiate(shells[1], spawnpoint, transform.rotation);
  38.  
  39. float distance = Vector2.Distance(enemys[i].transform.position, transform.position);
  40. //if (distance <= 5f)
  41. shells[0].transform.LookAt(enemys[i].transform);
  42. transform.position = Vector3.Lerp(shells[0].transform.position, enemys[i].transform.position,
  43. (Random.Range(6F, 10F) * distance) * Time.fixedDeltaTime);
  44. shells[1].transform.LookAt(enemys[i].transform);
  45. transform.position = Vector3.Lerp(shells[1].transform.position, enemys[i].transform.position,
  46. (Random.Range(6F, 10F) * distance) * Time.fixedDeltaTime);
  47. }
  48. }
  49. }
  50. }
  51. }`
Add Comment
Please, Sign In to add comment