Good evening guys,
I have used a spawn script that i know works but for some reason my enemies are not spawning. I have created the empty gameobject and renamed it spawnpoint and duplicated that to create another one, i have then dragged this code on top of it:
using UnityEngine;
using System.Collections;
public class spawnenemy : MonoBehaviour
{
//array of our spawn points
public GameObject[] SpawnPoints;
//variables for spawn delay
private float nextSpawn = 0;
public float spawnRate = 2;
//amount of enemies
public int EnemiesAmount = 20;
//Enemy prefab
public GameObject ZombiePrefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
SpawnPoints = GameObject.FindGameObjectsWithTag("spawnpoint");
FirstWave();
}
void FirstWave(){
for (int i=0; i<EnemiesAmount; i++)
{
if (Time.time > nextSpawn EnemiesAmount > 0)
{
nextSpawn = Time.time + spawnRate;
GameObject pos = SpawnPoints[Random.Range (0, SpawnPoints.Length)];
Instantiate(ZombiePrefab, pos.transform.position, pos.transform.rotation);
EnemiesAmount--;
}
}
}
}
for some reason they are not generating, i have made sure i dropped the enemy prefab on it in the inspector but it does not want to move, i have added the lookat function to the enemy so when it does spawn it looks for the player, can someone suggest where i may be going wrong here. I have checked the inspector and the prefab is on there i cannot understand why they are not spawning the ememy wierd, am i missing something obvious.
kind regards
David ![]()