Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnZombies : MonoBehaviour
{
public int numberOfZombies = 5;//How many zombies do we want in our game?
private GameObject[] allWaypoints;// list to store all waypoints
private GameObject zombiePrefab;
//public static GameObject[] zombies;
public static GameObject[] ZombiesLocation;
// Use this for initialization
void Start()
{
allWaypoints = GameObject.FindGameObjectsWithTag("Waypoint");
zombiePrefab = GameObject.FindGameObjectWithTag("Zombie");
zombiePrefab.SetActive(false);
//for(int i=0; i< allWaypoints.Length; i++)
//{
// Debug.Log(allWaypoints[i].transform.position);
//}
}
// Update is called once per frame
void Update()
{
//using a counter of the amount of zombies we have at the moment. We want to avoid having to do GameObject.find too many times
int nrZombiesExist = GameObject.FindGameObjectsWithTag("Zombie").Length;
//Debug.Log(nrZombiesExist);
while (nrZombiesExist < numberOfZombies)
{
//if (allWaypoints.Length > 1)
//{
//instatiates a copy of zombiePrefab. I places it at the position of one of the waypoints (randomly picks an index in the waypoint array). It gives it a new rotation and adds the object that this script is attached to as parent
Instantiate(zombiePrefab, allWaypoints[Random.Range(0, allWaypoints.Length - 1)].transform.position, new Quaternion(), transform).SetActive(true);
//count them manually instead of calling FindGameObjectsWithTag every time
nrZombiesExist++;
}
}
}
// located the spawing
// 1, new zombie will brith on last zombies dead place.
// 2, random by waypoints
// 3,
// after zombie dead, will leave a mark, to learn where is dead often, and avoid