Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawners implement interface, use a chance #65

Merged
merged 2 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Resources/Prefabs/EnemySpawner.prefab

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

248 changes: 238 additions & 10 deletions Assets/Resources/Prefabs/Floor1.prefab

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Scripts/Enemy/EnemyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void Chase()

private void IdleMaster()
{
Collider[] players = Physics.OverlapSphere(transform.position, 27.14f, playerLayer);
Collider[] players = Physics.OverlapSphere(transform.position, 32f, playerLayer);
if (players.Length > 0)
{
StartChase(players[0].gameObject);
Expand Down
17 changes: 11 additions & 6 deletions Assets/Scripts/Enemy/EnemySpawner.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
namespace GudKoodi.DeeperSkeeper.Enemy
{
using System.Collections;
using Entity;
using Event;
using UnityEngine;

/// <summary>
/// Creates the designed enemy and destroys spawner.
/// </summary>
public class EnemySpawner : MonoBehaviour
public class EnemySpawner : MonoBehaviour, ISpawner
{
/// <summary>
/// List of enemies to choose from.
Expand All @@ -23,18 +24,22 @@ public class EnemySpawner : MonoBehaviour
[Range(0, 1)]
public float SpawnChange = 1.0f;

void Start()
/// <summary>
/// Spawns a single enemy if given percent is high enough.
/// </summary>
/// <param name="percent">Chance percent given for the call.</param>
public void Spawn(float percent)
{
// TODO: Choose random enemy from the list.
StartCoroutine(Wait());
if (this.SpawnChange > percent)
{
EnemyCreationRequested.Trigger(Enemies.Enemies[0], transform.position);
}
}

private IEnumerator Wait()
{
yield return new WaitForSeconds(0.3f);

EnemyCreationRequested.Trigger(Enemies.Enemies[0], transform.position);
Destroy(gameObject);
}
}
}
Loading