Created
March 9, 2016 23:24
-
-
Save moon-goon/a289913f8000a08b565a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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