Skip to content

Instantly share code, notes, and snippets.

@JonathanYin
Created October 28, 2017 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanYin/6e59c764f2b33790792cc574b89f1c77 to your computer and use it in GitHub Desktop.
Save JonathanYin/6e59c764f2b33790792cc574b89f1c77 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class EnemyManager : MonoBehaviour
{
public PlayerHealth playerHealth;
public GameObject enemy;
public float spawnTime = 3f;
public Transform[] spawnPoints;
void Start ()
{
InvokeRepeating ("Spawn", spawnTime, spawnTime);
}
void Spawn ()
{
if(playerHealth.currentHealth <= 0f)
{
return;
}
int spawnPointIndex = Random.Range (0, spawnPoints.Length);
Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment