Basis festgelegt
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemySpawner : MonoBehaviour
|
||||
{
|
||||
[Header("Enemy")]
|
||||
[SerializeField]
|
||||
private GameObject enemyPrefab;
|
||||
|
||||
[Header("Spawn")]
|
||||
[SerializeField]
|
||||
private Transform spawnPoint;
|
||||
|
||||
[SerializeField]
|
||||
private float minSpawnDelay = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
private float maxSpawnDelay = 2f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (enemyPrefab == null)
|
||||
{
|
||||
Debug.LogError(
|
||||
"EnemySpawner: Kein Enemy-Prefab zugewiesen!",
|
||||
this
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawnPoint == null)
|
||||
{
|
||||
Debug.LogError(
|
||||
"EnemySpawner: Kein SpawnPoint zugewiesen!",
|
||||
this
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
StartCoroutine(SpawnLoop());
|
||||
}
|
||||
|
||||
private IEnumerator SpawnLoop()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
float delay = Random.Range(
|
||||
minSpawnDelay,
|
||||
maxSpawnDelay
|
||||
);
|
||||
|
||||
yield return new WaitForSeconds(delay);
|
||||
|
||||
SpawnEnemy();
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnEnemy()
|
||||
{
|
||||
Instantiate(
|
||||
enemyPrefab,
|
||||
spawnPoint.position,
|
||||
spawnPoint.rotation
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user