Advertisement
Guest User

Untitled

a guest
May 25th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. --------------------------------------------------------------------------------------
  2. enemy
  3. --------------------------------------------------------------------------------------
  4. --------------------------------------------------------------------------------------
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8.  
  9. public class Enemy : MonoBehaviour
  10. {
  11. public float move_speed;
  12. public Transform enemy;
  13. public GameObject player;
  14.  
  15. void Awake()
  16. {
  17. move_speed = (Random.Range(1, 5));
  18. }
  19.  
  20. void Update()
  21. {
  22. enemy.position += transform.right * Time.deltaTime * move_speed;
  23. if (Input.GetMouseButtonDown(0))
  24. {
  25. Vector3 MousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  26. if (MousePos.x < 0.0f)
  27. {
  28. Destroy(this.gameObject);
  29. }
  30. }
  31.  
  32. if (enemy.position.x > -0.35f)
  33. {
  34. Destroy(gameObject);
  35. Destroy(player);
  36. }
  37. }
  38. }
  39.  
  40. --------------------------------------------------------------------------------------
  41. spawn
  42. --------------------------------------------------------------------------------------
  43. --------------------------------------------------------------------------------------
  44. using UnityEngine;
  45. using System.Collections;
  46. using System.Collections.Generic;
  47.  
  48. public class EnemyManager : MonoBehaviour
  49. {
  50. public GameObject enemy_prefab;
  51. public List<GameObject> enemy;
  52. public float delayBetweenWaves = 15f;
  53. public int currentWave = 1;
  54. public Vector3 spawn_point;
  55. public Vector3 enemy_look;
  56.  
  57. public float cellX = 1f;
  58. public float cellY = 1f;
  59.  
  60. public bool waitForEnemys = true;
  61.  
  62. void Start()
  63. {
  64. Spawn();
  65. }
  66.  
  67. void Update()
  68. {
  69. if (waitForEnemys) return;
  70.  
  71. if (enemy.Count == 0)
  72. {
  73. currentWave++;
  74. waitForEnemys = true;
  75. StartCoroutine(NextWave());
  76. }
  77. }
  78.  
  79.  
  80. private void Spawn()
  81. {
  82. enemy.Clear();
  83. int enemyCount = currentWave * 3;
  84. for (int i = 0; i < enemyCount; i++)
  85. {
  86. GameObject z = (GameObject)Instantiate(enemy_prefab,
  87. GetSpawnPoint(i, enemyCount),
  88. GetSpawnDirection(i));
  89. enemy.Add(z);
  90. }
  91. waitForEnemys = false;
  92. }
  93.  
  94. private Quaternion GetSpawnDirection(int num)
  95. {
  96. return Quaternion.Euler(enemy_look - spawn_point);
  97. }
  98.  
  99. private Vector3 GetSpawnPoint(int num, int max)
  100. {
  101. int q1 = (int)Mathf.Sqrt(max);
  102. float q2 = Mathf.Sqrt(max);
  103. q1 = (q1 != q2 ? q1 + 1 : q1);
  104.  
  105. return (spawn_point +
  106. new Vector3(cellX * (num % q1),
  107. 0f,
  108. cellY * (num / q1)));
  109. }
  110.  
  111. IEnumerator NextWave()
  112. {
  113. float time = 0;
  114. do
  115. {
  116. time += Time.deltaTime;
  117. yield return null;
  118. } while (time < delayBetweenWaves);
  119. Spawn();
  120. }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement