random stuff i forgot to commit
This commit is contained in:
parent
274af1e5a1
commit
b0625ae834
59 changed files with 7806 additions and 664 deletions
102
Assets/Scripts/WaveManager.cs
Normal file
102
Assets/Scripts/WaveManager.cs
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class WaveManager : MonoBehaviour
|
||||
{
|
||||
|
||||
#region Statication
|
||||
|
||||
public static WaveManager instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance != null && instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class Wave
|
||||
{
|
||||
public Enemy[] enemies;
|
||||
}
|
||||
[Header("Player Point")]
|
||||
[SerializeField] private Transform tlPoint;
|
||||
[SerializeField] private Transform brPoint;
|
||||
|
||||
[Header("Enemy Point")]
|
||||
[SerializeField] private Transform enemyTLPoint;
|
||||
[SerializeField] private Transform enemyBRPoint;
|
||||
public Transform enemySpawnPoint;
|
||||
[Header("Waves")]
|
||||
[SerializeField] private TextMeshProUGUI waveUI;
|
||||
public int wave = 1;
|
||||
public Wave[] waveList;
|
||||
[Header("Enemies")]
|
||||
public Transform enemyFolder;
|
||||
public List<Enemy> enemiesInPlay = new();
|
||||
[SerializeField] private float enemyCheckRadius;
|
||||
[SerializeField] private LayerMask enemyLayer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SpawnWave();
|
||||
}
|
||||
|
||||
public Vector3 GetRandomPlayerPoint()
|
||||
{
|
||||
return new Vector3(Random.Range(tlPoint.position.x, brPoint.position.x),
|
||||
Random.Range(brPoint.position.y, tlPoint.position.y), 0);
|
||||
}
|
||||
|
||||
private Vector3 GetRandomEnemyPoint()
|
||||
{
|
||||
Vector3 randomPoint;
|
||||
do
|
||||
{
|
||||
randomPoint = new Vector3(Random.Range(enemyTLPoint.position.x, enemyBRPoint.position.x),
|
||||
Random.Range(enemyBRPoint.position.y, enemyTLPoint.position.y), 0);
|
||||
} while (CheckEnemyOverlap(randomPoint));
|
||||
return randomPoint;
|
||||
}
|
||||
|
||||
private bool CheckEnemyOverlap(Vector3 areaToCheck)
|
||||
{
|
||||
if (Physics2D.OverlapCircle(areaToCheck, enemyCheckRadius, enemyLayer))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SpawnWave()
|
||||
{
|
||||
waveUI.text = $"Wave: {wave}";
|
||||
foreach (Enemy enemy in waveList[wave-1].enemies)
|
||||
{
|
||||
Enemy newEnemy = Instantiate(enemy, enemyFolder);
|
||||
newEnemy.StartCoroutine(newEnemy.MoveToPosition(GetRandomEnemyPoint()));
|
||||
enemiesInPlay.Add(newEnemy);
|
||||
newEnemy.isStalled = true;
|
||||
}
|
||||
wave++;
|
||||
}
|
||||
|
||||
public void UpdateKills()
|
||||
{
|
||||
if (enemiesInPlay.Count == 0)
|
||||
{
|
||||
SpawnWave();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue