Add spawners
This commit is contained in:
parent
0f42de39e1
commit
b872cf3f5a
@ -24,7 +24,7 @@ GameObject:
|
|||||||
- component: {fileID: 592487110401094205}
|
- component: {fileID: 592487110401094205}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Enemy (Default Melee)
|
m_Name: Enemy (Default Melee)
|
||||||
m_TagString: Untagged
|
m_TagString: Enemy
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
|
35
Assets/Scripts/EnemySpawner.cs
Normal file
35
Assets/Scripts/EnemySpawner.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/EnemySpawner.cs.meta
Normal file
11
Assets/Scripts/EnemySpawner.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3adf9e5649b7c874f9f5ef2a5d70f99a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -5,6 +5,7 @@ TagManager:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
tags:
|
tags:
|
||||||
- Environment
|
- Environment
|
||||||
|
- Enemy
|
||||||
layers:
|
layers:
|
||||||
- Default
|
- Default
|
||||||
- TransparentFX
|
- TransparentFX
|
||||||
|
Loading…
Reference in New Issue
Block a user