43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EnemySpawn : MonoBehaviour
|
|
{
|
|
public int maxNum;
|
|
public int currentNum;
|
|
public float time;
|
|
private float timer;
|
|
public GameObject enemyPrefab;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (currentNum < maxNum)
|
|
{
|
|
timer += Time.deltaTime;
|
|
if (timer > time)
|
|
{
|
|
Vector3 pos = transform.position;
|
|
pos.x += Random.Range(-300, 300);
|
|
pos.z += Random.Range(-300, 300);
|
|
GameObject enemy = GameObject.Instantiate(enemyPrefab, pos, Quaternion.identity);
|
|
enemy.GetComponent<Enemy>().enemySpawn = this;
|
|
enemy.transform.parent = transform;
|
|
timer = 0;
|
|
currentNum++;
|
|
|
|
}
|
|
}
|
|
}
|
|
public void MinusNum()
|
|
{
|
|
currentNum--;
|
|
}
|
|
}
|