using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class peopleSpawn : MonoBehaviour
{

    
    public GameObject spawnerR;
    public GameObject spawnerL;

    public GameObject ringer;
    public GameObject passer;

    public float maxTime = 20;
    public float minTime = 5;
    private float time;
     private float spawnTime;
    // Start is called before the first frame update
    void Start()
    {
        SetRandomTime();
        time = 0;
    }

    void SetRandomTime()
    {
        spawnTime = Random.Range(minTime, maxTime);
        Debug.Log("Next object spawn in " + spawnTime + " seconds.");
    }

    // Update is called once per frame
    void FixedUpdate ()
     {
         //Counts up
         time += Time.deltaTime;
         //Check if its the right time to spawn the object
         if (time >= spawnTime) {
            //  Debug.Log ("Time to spawn: " + enemy.name);
            if(!(GameObject.Find("passer(Clone)")||GameObject.Find("ringer(Clone)"))){
                Spawn ();
                SetRandomTime ();
                time = 0;
            }
             
         }
     }

    void Spawn(){
        GameObject person=passer;

        int opc;
        opc=Random.Range(1,3);
        
        switch (opc)
        {
            case 1: 
                person=ringer;
                break;
            case 2: 
                person=passer;
                break;
            default:
                break;
        }

        opc=Random.Range(1,3);

        switch (opc)
        {
            case 1: 
                Instantiate(person, spawnerR.transform.position, spawnerR.transform.rotation);
                break;
            case 2: 
                Instantiate(person, spawnerL.transform.position, spawnerL.transform.rotation);
                break;
            default:
                break;
        }
        
    }
}
