Skip to content

Instantly share code, notes, and snippets.

@moon-goon
Created March 9, 2016 23:24
Show Gist options
  • Save moon-goon/a289913f8000a08b565a to your computer and use it in GitHub Desktop.
Save moon-goon/a289913f8000a08b565a to your computer and use it in GitHub Desktop.
using UnityEngine;
public class Spawn_Manager : MonoBehaviour {
public Transform[] spawnPoints;
public float invokeTime;
public GameObject spawnObjects;
public int maxInvoke;
private int invokeCount;
void Start() {
invokeCount = 0;
InvokeRepeating("onSpawn", 3.0F, invokeTime);
}
void Update() {
if (invokeCount == maxInvoke) {
CancelInvoke("onSpawn");
}
}
void onSpawn() {
for (int i = 0; i < spawnPoints.Length; i++) {
//This quaternion corresponds to "no rotation" the object is perfectly aligned with the world or parent axes.
//Side note : if you want to load a prefab from your game folder it has to be in Resources/foldername
//Resources.Load(foldername/prefabname)
//optional : as GameObject (cast it)
Instantiate(spawnObjects, spawnPoints[i].position, Quaternion.identity);
}
invokeCount++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment