GotNoPockets / MayhemJamGameThingy / Assets / Scripts / DoorOneScript.cs
DoorOneScript.cs
Raw
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DoorOneScript : MonoBehaviour
{
	public GameObject Door;
	public List<GameObject> Triggers;
	private AudioManager Audio;


	private void Start()
	{
		Audio = FindObjectOfType<AudioManager>();
	}

	private void Update()
	{
		if (DoorOpen())
		{
			Door.GetComponent<Animator>().SetBool("OpenDoor", true);
			Door.GetComponent<Animator>().SetBool("CloseDoor", false);
		}
		else
		{
			if (Door.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName("Open"))
			{
				Door.GetComponent<Animator>().SetBool("OpenDoor", false);
				Door.GetComponent<Animator>().SetBool("CloseDoor", true);
			}
		}
	}

	private bool DoorOpen()
	{
		int AllActive = Triggers.Count;
		int CurrentActive = 0;

		for (int i = 0; i < Triggers.Count; i++)
		{
			if (Triggers[i].GetComponent<TriggerScript>().HasTriggered)
			{
				CurrentActive++;
			}
		}

		if (AllActive == CurrentActive)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

}