using UnityEngine;
using System.Collections;
using System;

public class SpawnCiviliansScript : MonoBehaviour {

    public GameObject[] civiliansArray;
    public float spawnTime = 0;

    private int _prefabsCount;
    private float _timeWaiting = 0;

	// Use this for initialization
	void Start () {
        _prefabsCount = civiliansArray.Length;
	}
	
	// Update is called once per frame
	void Update () {

        if (spawnTime == 0 || _prefabsCount == 0)
            return;

        _timeWaiting += Time.deltaTime;

        if (_timeWaiting >= spawnTime)
        {
            _timeWaiting = 0;

            UnityEngine.Random.seed = System.DateTime.Now.Second;
            int l_index = (int)(UnityEngine.Random.value * _prefabsCount);

            Instantiate(civiliansArray[l_index], transform.position, Quaternion.identity);
        }

	}
}
