Skip to content

Instantly share code, notes, and snippets.

@TheCuttlefish
Created May 24, 2021 15:29
Show Gist options
  • Save TheCuttlefish/2edca0a49425897fc302a6a8698be2a2 to your computer and use it in GitHub Desktop.
Save TheCuttlefish/2edca0a49425897fc302a6a8698be2a2 to your computer and use it in GitHub Desktop.
Enemy Spawner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
public List<GameObject> spawnPoints = new List<GameObject>();
public GameObject enemy;
int randSpawnPoint;
float timer;
public float spawnDelay = 1f;
void Update()
{
timer += Time.deltaTime;
if (timer > spawnDelay)
{
randSpawnPoint = Random.Range(0, spawnPoints.Count);
GameObject enemyInstance = Instantiate(enemy, spawnPoints[randSpawnPoint].transform.position, Quaternion.identity);
enemyInstance.transform.parent = null;
timer = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment