Increase List of Spawns Dynamically
Hello, I've been using some code (which I take no credit for using) which spawns enemies at set spawn points, at set intervals.
I have now included "blockages" to parts of the map. Meaning the player must remove them if they want to advance to a new part of the map.
Now I was hoping to make Spawn Points become "active" or "enabled" as the player removes these blockages. Pretty much like Call Of Duty: Zombies.
A huge thanks in advance if you can help me.
P.S: This is the spawning code that I have currently. using UnityEngine; using System.Collections;
public class SpawnWaveGenerator : MonoBehaviour
{
[System.Serializable]
public class enemy
{
public string name;
public GameObject prefab;
public float chance;
public float delayTime;
}
public Transform[] points;
public enemy[] enemies;
public int SpawnTimer;
enemy chosenEnemy;
float random;
float cumulative;
void Start()
{
SpawnTimer = 0;
}
void Update()
{
SpawnTimer = SpawnTimer + 1;
if (SpawnTimer >= 100)
{
SpawnRandom();
SpawnTimer = 0;
}
}
void SpawnRandom()
{
random = Random.value;
cumulative = 0f;
for (int i = 0; i < enemies.Length; i++)
{
cumulative += enemies[i].chance;
if (random < cumulative && Time.time >= enemies[i].delayTime)
{
chosenEnemy = enemies[i];
break;
}
}
Instantiate(chosenEnemy.prefab, points[Random.Range(0, points.Length)].position, points[Random.Range(0, points.Length)].rotation);
}
}
Answer by phil_me_up · Feb 16, 2016 at 02:02 PM
If you're asking how to enable / disable spawn points depending on progression within the game, then there are a number of possible ways.
One might be to have a spawn point manager which simple enables / disables the spawn objects (either the game object they are attached to or the component).
Another would be to simply have an 'active' variable in the spawn script which you change and test for in your updates.
Another would be to give each spawn script an 'active at' variable which is tested for. When the player hits level 4, any spawn point with an 'active at' value of 4 or greater would then allow spawns to occur.
These are just a few ways, the best way really does depend on your game but I'd probably have a spawn point manger which tracks all the spawn points and either enables / disables them, or just serves as a way of requesting / updating the current game progression.
Your answer
Follow this Question
Related Questions
Endless Runner with new Biome each time 0 Answers
All crops in list growing at once when they are supposed to grow individually 0 Answers
Copying a list of lists of int's in c# 1 Answer
Trying to program two buttons to appear when the player in my game dies 0 Answers
Only spawning power ups that the player wants in that game 1 Answer