根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:
``` docs(readme): 更新文档说明 - 添加项目使用指南 - 完善API接口说明 - 修正错误的配置示例 ``` 注意:由于您提供的code differences部分为空,以上是一个示例模板。当您有具体的代码变更时,请提供详细的变更内容以便生成更准确的commit message。
This commit is contained in:
1 parent
8d58c2223c
commit
11f1af357d
191 files changed
+2315
-1539
No files matched your search
@@ -0,0 +1,116 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WaveSpawner : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Wave
|
||||
{
|
||||
public string waveName = "第一波";
|
||||
public GameObject[] enemyPrefabs;
|
||||
public Vector3[] spawnPositions;
|
||||
public float spawnDelay = 0.5f;
|
||||
}
|
||||
|
||||
[Header("波次配置")]
|
||||
public Wave[] waves;
|
||||
|
||||
[Header("触发设置")]
|
||||
public float triggerZPosition = 20f;
|
||||
public bool autoStart = false;
|
||||
|
||||
private int currentWave = 0;
|
||||
private bool waveStarted = false;
|
||||
private bool waveCompleted = false;
|
||||
private List<GameObject> activeEnemies = new List<GameObject>();
|
||||
private Transform player;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
player = GameObject.FindGameObjectWithTag("Player")?.transform;
|
||||
if (player == null)
|
||||
{
|
||||
player = FindObjectOfType<MainCharacterCombat>()?.transform;
|
||||
}
|
||||
|
||||
if (autoStart)
|
||||
{
|
||||
StartWave();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!waveStarted && !waveCompleted && player != null)
|
||||
{
|
||||
if (player.position.z >= triggerZPosition)
|
||||
{
|
||||
StartWave();
|
||||
}
|
||||
}
|
||||
|
||||
if (waveStarted && !waveCompleted)
|
||||
{
|
||||
CleanupDestroyedEnemies();
|
||||
|
||||
if (activeEnemies.Count == 0)
|
||||
{
|
||||
CompleteWave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void StartWave()
|
||||
{
|
||||
if (currentWave >= waves.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
waveStarted = true;
|
||||
StartCoroutine(SpawnWave(waves[currentWave]));
|
||||
}
|
||||
|
||||
private IEnumerator SpawnWave(Wave wave)
|
||||
{
|
||||
Debug.Log($"开始生成:{wave.waveName}");
|
||||
|
||||
int count = Mathf.Min(wave.enemyPrefabs.Length, wave.spawnPositions.Length);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (wave.enemyPrefabs[i] != null)
|
||||
{
|
||||
Vector3 spawnPos = transform.position + wave.spawnPositions[i];
|
||||
GameObject enemy = Instantiate(wave.enemyPrefabs[i], spawnPos, Quaternion.identity);
|
||||
enemy.tag = "Enemy";
|
||||
|
||||
activeEnemies.Add(enemy);
|
||||
|
||||
Debug.Log($"生成敌人:{enemy.name} 位置={spawnPos}");
|
||||
|
||||
yield return new WaitForSeconds(wave.spawnDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanupDestroyedEnemies()
|
||||
{
|
||||
activeEnemies.RemoveAll(enemy => enemy == null);
|
||||
}
|
||||
|
||||
private void CompleteWave()
|
||||
{
|
||||
waveCompleted = true;
|
||||
Debug.Log($"完成:{waves[currentWave].waveName}");
|
||||
}
|
||||
|
||||
public void NextWave()
|
||||
{
|
||||
currentWave++;
|
||||
waveStarted = false;
|
||||
waveCompleted = false;
|
||||
activeEnemies.Clear();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user