using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemySpawing : MonoBehaviour
{
public GameObject enemy;
public float respawnTime = 1.0f;
private Vector2 screenBounds;
// Use this for initialization
void Start()
{
screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
StartCoroutine(enemySpawning());
}
private void spawnEnemy()
{
GameObject a = Instantiate(enemy) as GameObject;
a.transform.position = new Vector2(screenBounds.x * -2, Random.Range(-screenBounds.y, screenBounds.y));
}
IEnumerator enemySpawning()
{
while (true)
{
yield return new WaitForSeconds(respawnTime);
spawnEnemy();
}
}
}