I have two types of enemies and four enemy spawn positions(each types has two spawn position). I want that a new enemy spawn when the player and one of the 4 enemies is dead and at least one of the four spawn position is empty.
The script is attachted to one of the enemy spawn position and it only work for the one(I know that the enemycount is different, that was just a prototype script):
using UnityEngine;
using System.Collections;
public class EnemyCount : MonoBehaviour {
public int enemyCount = 2;
public GameObject spawnObject; //public GameObject[] spawnObject;
public Transform spawnPosition; //public Transform[] spawnPosition;
private int i = 0;
public HealthController healthController;
// Use this for initialization
void Start () {
spawnObject.GetComponent().enemycount = GameObject.Find("EnemySpawn");
spawnObject.GetComponent().expSystem = GameObject.Find("Player");
spawnObject.GetComponent ().expSystem = GameObject.Find ("Player");
spawnObject.GetComponent ().enemycount = GameObject.Find ("EnemySpawn");
spawnObject.transform.GetChild (0).GetComponent ().controller = GameObject.Find ("Player");
}
// Update is called once per frame
void Update () {
if(enemyCount <= 1 && healthController.respawn)
{
Spawn();
}
}
void Spawn()
{
if(enemyCount <= 1)
{
enemyCount = 2;
Instantiate(spawnObject,spawnPosition.position,Quaternion.identity);
}
}
}
↧