Open-sourced some code

This commit is contained in:
2019-03-08 09:54:14 +11:00
commit 645272872c
142 changed files with 3028 additions and 0 deletions
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TimedSpawner : MonoBehaviour {
//inspector access elements
public GameObject prefab;
public float spawnDelay = 10f;
public int maxSpawns = 3;
//private members
float lastSpawnTime = float.NegativeInfinity;
List<GameObject> spawnList = new List<GameObject>();
//TODO: maybe all spawners should shut off (and monsters become inactive) when the player is too far away.
void Update() {
//prune the list
spawnList.RemoveAll(spawn => spawn == null);
//spawn if enough time has passed
if (Time.time - lastSpawnTime > spawnDelay && spawnList.Count < maxSpawns) {
lastSpawnTime = Time.time;
spawnList.Add(Instantiate(prefab, transform.position, Quaternion.identity, transform));
}
}
}