Hi, I’ve been trying to write a script for my (ZombieStyle) FPS so when the game first loads, several “enemies” will be spawned at random spawn points I have set throughout my map. (I used empty GameObjects) I want a lot of zombies walking around aimless (Have already written the AI all works fine) I just want it to be completely random so while playing I don’t learn where I will find them. I want it random.
Also if I start killing zombies to quickly then there wont be any left and thats boring. So how would I make it to where if there are less that however many zombies, Instantiate however many(Random.Range maybe). Just something to keep a decent amount of zombies on the street. Sorry to ask for a script, but I’ve been searching for the past 4 hours and trying with the API and can’t seem to make anything work.
Here is what I have so far, I have no clue what I am doing so I started it off as spawning just 1 prefab. I can’t figure out how to make Instantiate work, it says it requires 4 arguements or something. If you can write it to spawn alot when the game starts that would help.
PS: My game is all in C#
using UnityEngine;
using System.Collections;
/// <summary>
/// This is the EnemySpawn script.
/// This script is attached to the SpawnManager(EmptyGameObject).
/// </summary>
public class EnemySpawn : MonoBehaviour {
//--------------Variables Start-----------------
private GameObject[] enemySpawnPoints;
private int enemySpawnGroup = 0;
public Transform enemyAI;
public bool iAmAnEnemy = false;
//--------------Variables End------------------
void Awake()
{
//Call the SpawnEnemy function.
SpawnEnemy();
}
// Use this for initialization.
void Start () {
}
// Update is called once per frame.
void Update () {
}
void SpawnEnemy ()
{
//Find all of the enemy spawn points and place a reference to them in the array
//enemySpawnPoints.
enemySpawnPoints = GameObject.FindGameObjectsWithTag("SpawnEnemy");
//Randomly select one of those spawn points.
GameObject randomEnemySpawn = enemySpawnPoints[Random.Range(0, enemySpawnPoints.Length)];
//Instantiate the enemy at the randomly selected spawn point.
Instantiate(enemyAI, randomEnemySpawn.transform.position,
randomEnemySpawn.transform.rotation, enemySpawnGroup);
}
}