diff --git a/Assets/Prefabs/Enemies/Enemy (Default Melee).prefab b/Assets/Prefabs/Enemies/Enemy (Default Melee).prefab index ec3bc8e..fc76233 100644 --- a/Assets/Prefabs/Enemies/Enemy (Default Melee).prefab +++ b/Assets/Prefabs/Enemies/Enemy (Default Melee).prefab @@ -24,7 +24,7 @@ GameObject: - component: {fileID: 592487110401094205} m_Layer: 0 m_Name: Enemy (Default Melee) - m_TagString: Untagged + m_TagString: Enemy m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Scripts/EnemySpawner.cs b/Assets/Scripts/EnemySpawner.cs new file mode 100644 index 0000000..79445eb --- /dev/null +++ b/Assets/Scripts/EnemySpawner.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Saltosion.OneWeapon { + public class EnemySpawner : MonoBehaviour { + public GameObject[] EnemyPrefabs; + public float SpawnCooldown = 5.0f; + public float SpawnChance = 0.5f; + public int MaxEnemiesWhenSpawning = 5; + public float Radius = 4; + + private float SpawnTime = 0.0f; + + private void Update() { + if (SpawnTime > 0) { + SpawnTime -= Time.deltaTime; + } else { + GameObject[] Enemies = GameObject.FindGameObjectsWithTag("Enemy"); + if (Enemies.Length < 5 && Random.value < SpawnChance) { + float DirectionRadians = Random.value * Mathf.PI * 2.0f; + Vector2 Direction = new Vector2(Mathf.Cos(DirectionRadians), Mathf.Sin(DirectionRadians)); + float Distance = Random.value * Radius; + Instantiate(EnemyPrefabs[(int)(Mathf.Min(0.99f, Random.value) * EnemyPrefabs.Length)], (Vector2)transform.position + Direction * Distance, new Quaternion(), null); + } + SpawnTime = SpawnCooldown; + } + } + + private void OnDrawGizmosSelected() { + Gizmos.color = Color.green; + Gizmos.DrawWireSphere(transform.position, Radius); + } + } +} diff --git a/Assets/Scripts/EnemySpawner.cs.meta b/Assets/Scripts/EnemySpawner.cs.meta new file mode 100644 index 0000000..5eb6b1b --- /dev/null +++ b/Assets/Scripts/EnemySpawner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3adf9e5649b7c874f9f5ef2a5d70f99a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index e33ee85..adbaaac 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -5,6 +5,7 @@ TagManager: serializedVersion: 2 tags: - Environment + - Enemy layers: - Default - TransparentFX