Hi
Im making a online zombie survival game, i have zombies that walk and do damage, but they dont spawn.
im trying to make a script that spawn New zombies infinity, so maybe at the start its only a few but more and more spawn and after awhile the players have a serious problem With surviving.
Im a little New too scripting so i would really appreciate some help.
I trying too read in referance and using the forum and Google but cant find exactly what im looking for.
Thank you for Reading and maybe helping me !
Im not asking someone too do it for me, just a point in the right direction !
create a prefab for the spawner then you can place as many of these prefabs as you want:
Put an empty game object in your scene and call it ZombieSpawner, attach this script to the empty game object:
using UnityEngine;
using System.Collections;
public class ZombieSpawnScript : MonoBehaviour
{
public Object zombie; // Zombie prefabs to instantiate
public float spawninterval; // delay between spawns
public float nextspawn; // when next spawn is due
// Use this for initialization
void Start ()
{
nextspawn = Time.time+spawninterval; // set initial next spawn time
}
// Update is called once per frame
void Update ()
{
if(Time.time > nextspawn)
{
nextspawn = Time.time+spawninterval; // set next spawn time
SpawnZombie(); // call spawn method
}
}
void SpawnZombie()
{
Instantiate(zombie,transform.position, transform.rotation); // create zombie
}
}
And drag the zombie prefab into its slot in the inspector and set the time in seconds between each spawn
Thank you so mutch ! you saved me so mutch time, it Works Perfect !
No problem, glad to have helped.
Now kill those zombies!