Last active
August 29, 2015 14:16
-
-
Save niorad/61b66f9c5ba09b41db13 to your computer and use it in GitHub Desktop.
Prefab Instantiation Script for Unity3D. Has rounds and pauses between rounds.
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; | |
using System.Collections; | |
public class SpawnPrefab : MonoBehaviour { | |
public Transform prefabSpawnee; | |
public float interval = 1; | |
public int instancesPerRound = 5; | |
public float pauseBetweenRounds = 3f; | |
private int shotInRound = 0; | |
private bool isActive = true; | |
void Start () { | |
ActivateSpawner(); | |
} | |
void Spawn () { | |
if(isActive) { | |
Transform prefabInstance; | |
prefabInstance = Instantiate(prefabSpawnee, transform.position, transform.rotation) as Transform; | |
shotInRound++; | |
} | |
} | |
void ActivateSpawner() { | |
InvokeRepeating("Spawn", 0, interval); | |
} | |
void Update() { | |
if(shotInRound == instancesPerRound) { | |
CancelInvoke("Spawn"); | |
shotInRound = 0; | |
Invoke ("ActivateSpawner", pauseBetweenRounds); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment