- Home /
Spawn fixed number of enemies on fixed spawn points using a fixed delay
As my title said:
I'm trying to spawn a fixed number of ennemies, forming a wave of enemies. There will be five points from which they will be able to spawn. I'd like them to choose a random point from which to start, then spawn one after another until they are all there. The delay will be fixed as well, about 3 or 4 secondes.
Do I need a script? Is there any tutorial available? Any help?
Thanks!
Answer by poncho · Mar 02, 2012 at 09:08 PM
yes, you need a script, using unity without scripting is almoust impossible for this you will need - an array of your spawn positions - a method to be invoked every 3 or 4 seconds - instantiating your enemy at one of your spawn positions
for the tutorials i would recommend how to programm for dummies to learn the basic concept about programming then you could use google and unity script reference to anything yo want to do with unity
Answer by Herve_Simard · Mar 03, 2012 at 03:22 PM
Not bad, I'll try this, that's a good way to start. As for programming, don't worry, it might be okay. Thanks! I'll give an update if I do anything good.
Answer by Herve_Simard · Mar 04, 2012 at 07:37 PM
I'd like to know now how to link an array of spawnpositions into an instantiate...
I've tried this:
public class SpawnScript : MonoBehaviour { public int NumberEnemies;
public float SpawnTimer;
public float SpawnCountdown = 240.0f;
private Transform[] SpawnPoints;
private Transform[] Enemy;
private bool canSpawn = false;
void Start()
{
}
void SpawnEnemy()
{
// Mettre un index en paramètre de mes tableaux.
Instantiate(Enemy[0], SpawnPoints[0], Quaternion.identity);
NumberEnemies += 1;
SpawnTimer = 0.0f;
}
void Update ()
{
while(NumberEnemies != 7)
{
SpawnTimer = 0.0f;
SpawnTimer += Time.deltaTime;
if(SpawnTimer >= SpawnCountdown)
{
SpawnEnemy();
}
}
}
}
But it keeps on giving me this kind of error:
Assets/Scripts/SpawnScript.cs(24,17): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)' has some invalid arguments
And I've yet to figure why it's happening...
Your answer
Follow this Question
Related Questions
Timer Spawn Freezing Unity C# 1 Answer
Timer to call Instantiate 1 Answer
Timer with 5-6 rounds that spawns enemies then end game 0 Answers
Random spawn timer 1 Answer