using UnityEngine;

namespace GGJam21.Core
{
    public class SwitchController : MonoBehaviour
    {
        public GameObject[] obstacles;
        public SwitchController button;
        public Material normal;
        public Material transparent;
        
        private void OnTriggerEnter(Collider other)
        {
            if (CompareTag("Switch") && other.CompareTag("Player"))
            {
                foreach (GameObject go in obstacles)
                {
                    go.GetComponent<Renderer>().material = transparent;
                    go.GetComponent<Collider>().isTrigger = true;
                }
               
                button.GetComponent<Renderer>().material = transparent;
            }
            if (CompareTag("Switch2") && other.CompareTag("Player"))
            {
                foreach (GameObject go in obstacles)
                {
                    go.GetComponent<Renderer>().material = normal;
                    go.GetComponent<Collider>().isTrigger = false;
                }

                button.GetComponent<Renderer>().material = transparent;
            }
        }

        private void OnTriggerEnterExit(Collider other)
        {
            button.GetComponent<Renderer>().material = normal;
        }
    }
}