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();
}
}
}
How do you spawn your objects? I assume its a script on the original sprite, probably within the update() function. If so, then after deleting your original, unity stops calling the update() function. If not, then please update your script, as you are destroying "enemy.gameobject", instead of the actual collision object "other".
– Klarzahs