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

public class Tunnel : MonoBehaviour
{
    public Gate beforeChunk;
    public Gate afterChunk;

    private int onTrigger = 0;

	void Start ()
    {
        beforeChunk.OpenGate();
        afterChunk.CloseGate();
	}

    private void Update()
    {
        if(onTrigger == SGDungeonGameplayManager.Instance.Dwarfs.Count)
        {
            beforeChunk.CloseGate();
            afterChunk.OpenGate();
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if(other.GetComponent<SGDDwarf>() != null)
        {
            onTrigger++;
        }
    }
    private void OnTriggerExit(Collider other)
    {
        if (other.GetComponent<SGDDwarf>() != null)
        {
            onTrigger--;
        }
    }
}
