Added wave spawner
This commit is contained in:
parent
5e36616873
commit
32e28f156e
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 357d89feb38affe49b5f3813d110de48
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "data", menuName = "Zhen/SpawnerList")]
|
||||
public class EnemyList : ScriptableObject
|
||||
{
|
||||
public EnemyPrefabInfo[] List;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct EnemyPrefabInfo
|
||||
{
|
||||
public GameObject prefab;
|
||||
public float Difficulty;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: af7974227ca2b6c4eb332e658d94fc34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "data", menuName = "Zhen/SpawnerList", Order = 1)]
|
||||
public class EnemyList : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class NewBehaviourScript : MonoBehaviour
|
||||
{
|
||||
// Shared
|
||||
public int Wave = 0;
|
||||
public float difficulty = 0;
|
||||
|
||||
// Inspector
|
||||
[SerializeField] private float difficultyIncreasePerWave = 0.1f;
|
||||
[SerializeField] private float WaveTime;
|
||||
[SerializeField] private EnemyList enemyList;
|
||||
|
||||
// Private
|
||||
private bool nextWaveRequested = false;
|
||||
private float timer = 0f;
|
||||
|
||||
public void StartSpawning() => StartCoroutine(SpawnLoop());
|
||||
public void StartNextWave() => nextWaveRequested = true;
|
||||
|
||||
private IEnumerator SpawnLoop()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitUntil(() => timer > WaveTime || nextWaveRequested);
|
||||
|
||||
SpawnWave(difficulty);
|
||||
|
||||
Wave++;
|
||||
difficulty *= difficultyIncreasePerWave + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SpawnWave(float difficulty)
|
||||
{
|
||||
var decendingList = enemyList.List.OrderByDescending(x => x.Difficulty).ToArray();
|
||||
for (int i = 0; i < decendingList.Length; i++)
|
||||
{
|
||||
while (difficulty > decendingList[i].Difficulty)
|
||||
{
|
||||
Instantiate(decendingList[i].prefab);
|
||||
difficulty -= decendingList[i].Difficulty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a592fac78e06964b863b67047a446a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue