Greetings everybody, I did a spawner that spawns enemies. but the problem is it spawns the prefab enemy first and when im colliding with him no more enemies spawn, can you help me please?
BTW its Unity2D
I got 2 codes:
Spawner Code:
public GameObject enemy;
public float TimeBtwSpawn;
public float SpawnTime;
void Start() {
TimeBtwSpawn = SpawnTime;
}
void Update()
{
if (TimeBtwSpawn <= 0)
{
Instantiate(enemy, transform.position, Quaternion.identity);
TimeBtwSpawn = SpawnTime;
}
else {
TimeBtwSpawn -= Time.deltaTime;
}
}
Enemy Code:
public Rigidbody2D rb;
public float speed;
public GameObject effect;
public float EnemyHealth;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
rb.velocity = Vector2.right * speed ;
}
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Player")) {
Destroy(gameObject);
}
}