Advertisement
Guest User

Untitled

a guest
May 4th, 2021
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class spawnAsteroids : MonoBehaviour
  6. {
  7. public GameObject asteroidPreFab;
  8. public float respawnTime = 1.0f;
  9. private Vector2 screenBounds;
  10. void Start()
  11. {
  12. screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Mathf.Clamp(transform.position.x, -8f, 8f), Mathf.Clamp(transform.position.y, -10f, 10f), transform.position.z));
  13.  
  14. transform.position = new Vector3(Mathf.Clamp(transform.position.x, -8f, 8f), Mathf.Clamp(transform.position.y, -8f, 10f), transform.position.z);
  15.  
  16. StartCoroutine(asteroidWave());
  17. }
  18. private void spawnEnemy()
  19. {
  20. GameObject a = Instantiate(asteroidPreFab) as GameObject;
  21.  
  22.  
  23. a.transform.position = new Vector2(Random.Range(8f, 10f) , Random.Range(-7f, 7f));
  24.  
  25. }
  26.  
  27. IEnumerator asteroidWave()
  28. {
  29. while (true)
  30. {
  31. yield return new WaitForSeconds(respawnTime);
  32. spawnEnemy();
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement