feat: enemies spawn in spawn zones and wander on a graph
This commit is contained in:
@@ -1,47 +1,65 @@
|
||||
using System.Collections.Generic;
|
||||
using Drawing;
|
||||
using Pathfinding;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemySpawn : MonoBehaviour{
|
||||
public float radius = 30f;
|
||||
namespace Reset.Units{
|
||||
public class EnemySpawn : MonoBehaviour{
|
||||
public float radius = 30f;
|
||||
|
||||
public int minimumEnemies = 1;
|
||||
public int maximumEnemies = 5;
|
||||
|
||||
public Vector2 enemyCount;
|
||||
public int minimumEnemies = 1;
|
||||
public int maximumEnemies = 5;
|
||||
|
||||
// TODO: Replace this with an Enemy selector based on difficulty, random chance, etc?
|
||||
public GameObject enemy;
|
||||
public Vector2 enemyCount;
|
||||
|
||||
public List<GameObject> enemies;
|
||||
|
||||
void Start(){
|
||||
SpawnEnemies();
|
||||
}
|
||||
// TODO: Replace this with an Enemy selector based on difficulty, random chance, etc?
|
||||
public GameObject enemy;
|
||||
|
||||
void SpawnEnemies(){
|
||||
int count = Random.Range(minimumEnemies, maximumEnemies + 1);
|
||||
public List<GameObject> enemies;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
Vector3 newPosition = transform.position;
|
||||
public GridGraph relatedGraph;
|
||||
|
||||
float randomX = Random.Range(-(radius / 2f), radius / 2f);
|
||||
float randomZ = Random.Range(-(radius / 2f), radius / 2f);
|
||||
void Start(){
|
||||
CreateAstarGraph();
|
||||
SpawnEnemies();
|
||||
}
|
||||
|
||||
newPosition += new Vector3(randomX, transform.position.y, randomZ);
|
||||
void CreateAstarGraph(){
|
||||
relatedGraph = AstarPath.active.data.AddGraph(typeof(GridGraph)) as GridGraph;
|
||||
|
||||
float randomRot = Random.Range(0f, 360f);
|
||||
relatedGraph.SetDimensions(Mathf.FloorToInt(radius) * 2, Mathf.FloorToInt(radius) * 2, 1f);
|
||||
relatedGraph.collision.diameter = 3f;
|
||||
|
||||
GameObject newEnemy = Instantiate(enemy, newPosition, Quaternion.AngleAxis(randomRot, Vector3.up));
|
||||
|
||||
enemies.Add(newEnemy);
|
||||
AstarPath.active.Scan(relatedGraph);
|
||||
|
||||
GetComponent<ProceduralGraphMover>().graph = relatedGraph;
|
||||
}
|
||||
|
||||
void SpawnEnemies(){
|
||||
int count = Random.Range(minimumEnemies, maximumEnemies + 1);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
Vector3 newPosition = transform.position;
|
||||
|
||||
float randomX = Random.Range(-(radius / 2f), radius / 2f);
|
||||
float randomZ = Random.Range(-(radius / 2f), radius / 2f);
|
||||
|
||||
newPosition += new Vector3(randomX, transform.position.y, randomZ);
|
||||
|
||||
float randomRot = Random.Range(0f, 360f);
|
||||
|
||||
GameObject newEnemy = Instantiate(enemy, newPosition, Quaternion.AngleAxis(randomRot, Vector3.up));
|
||||
newEnemy.GetComponent<Enemy>().relatedSpawner = this;
|
||||
|
||||
enemies.Add(newEnemy);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
Draw.WireCylinder(transform.position, transform.position + Vector3.up * 7f, radius);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Draw.WireCylinder(transform.position, transform.position + Vector3.up * 7f, radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user