Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class spawnAsteroids : MonoBehaviour
- {
- public GameObject asteroidPreFab;
- public float respawnTime = 1.0f;
- private Vector2 screenBounds;
- void Start()
- {
- screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Mathf.Clamp(transform.position.x, -8f, 8f), Mathf.Clamp(transform.position.y, -10f, 10f), transform.position.z));
- transform.position = new Vector3(Mathf.Clamp(transform.position.x, -8f, 8f), Mathf.Clamp(transform.position.y, -8f, 10f), transform.position.z);
- StartCoroutine(asteroidWave());
- }
- private void spawnEnemy()
- {
- GameObject a = Instantiate(asteroidPreFab) as GameObject;
- a.transform.position = new Vector2(Random.Range(8f, 10f) , Random.Range(-7f, 7f));
- }
- IEnumerator asteroidWave()
- {
- while (true)
- {
- yield return new WaitForSeconds(respawnTime);
- spawnEnemy();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement