Created
May 24, 2021 15:29
-
-
Save TheCuttlefish/2edca0a49425897fc302a6a8698be2a2 to your computer and use it in GitHub Desktop.
Enemy Spawner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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