enemies spawn with offsets in positions and animations
This commit is contained in:
parent
d1930a6b00
commit
53e7fc78a7
4 changed files with 35 additions and 12 deletions
|
|
@ -336,9 +336,12 @@ namespace TD.Gameplay
|
|||
{
|
||||
if (entry.EnemyType == null || entry.Count <= 0) continue;
|
||||
|
||||
for (int i = 0; i < entry.Count; i++)
|
||||
int chunkSize = Mathf.Max(1, entry.ChunkSize);
|
||||
for (int i = 0; i < entry.Count; i += chunkSize)
|
||||
{
|
||||
SpawnEnemyInAllZones(entry.EnemyType);
|
||||
int burst = Mathf.Min(chunkSize, entry.Count - i);
|
||||
for (int j = 0; j < burst; j++)
|
||||
SpawnEnemyInAllZones(entry.EnemyType, entry.SpawnSpread);
|
||||
|
||||
if (entry.SpawnInterval > 0f)
|
||||
yield return new WaitForSeconds(entry.SpawnInterval);
|
||||
|
|
@ -355,7 +358,7 @@ namespace TD.Gameplay
|
|||
|
||||
// ----- Spawn helpers ----------------------------------------------
|
||||
|
||||
private void SpawnEnemyInAllZones(EnemyDefinition def)
|
||||
private void SpawnEnemyInAllZones(EnemyDefinition def, float spawnSpread = 0f)
|
||||
{
|
||||
var loader = LevelLoader.Instance;
|
||||
if (loader?.LevelData?.PlayerZones == null) return;
|
||||
|
|
@ -376,11 +379,12 @@ namespace TD.Gameplay
|
|||
// this enemy for leak attribution — can't be derived from the spawner
|
||||
// tile's owner-grid entry because SpawnerVolume sits outside
|
||||
// PlayerZoneVolume (so OwnerGrid[spawnerTile] = None).
|
||||
SpawnEnemy(def, zone.Spawners[0].TilePosition, zone.Owner);
|
||||
SpawnEnemy(def, zone.Spawners[0].TilePosition, zone.Owner, spawnSpread);
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnEnemy(EnemyDefinition def, Vector2Int spawnerTile, PlayerSlot ownerSlot)
|
||||
private void SpawnEnemy(EnemyDefinition def, Vector2Int spawnerTile, PlayerSlot ownerSlot,
|
||||
float spawnSpread = 0f)
|
||||
{
|
||||
if (def.EnemyPrefab == null)
|
||||
{
|
||||
|
|
@ -388,10 +392,11 @@ namespace TD.Gameplay
|
|||
return;
|
||||
}
|
||||
|
||||
var go = Instantiate(
|
||||
def.EnemyPrefab,
|
||||
GridCoordinates.GridToWorld(spawnerTile),
|
||||
Quaternion.identity);
|
||||
Vector3 spawnPos = GridCoordinates.GridToWorld(spawnerTile);
|
||||
if (spawnSpread > 0f)
|
||||
spawnPos.x += Random.Range(-spawnSpread, spawnSpread);
|
||||
|
||||
var go = Instantiate(def.EnemyPrefab, spawnPos, Quaternion.identity);
|
||||
|
||||
var health = go.GetComponent<EnemyHealth>();
|
||||
var movement = go.GetComponent<EnemyMovement>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue