Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Mechanisms / HeavyPressurePlate.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HeavyPressurePlate : MonoBehaviour
{
    public List<GameObject> weights = new List<GameObject>();
    private List<GameObject> currentWeights = new List<GameObject>();

    private Triggers triggers;

    // Start is called before the first frame update
    void Start()
    {
        triggers = GetComponent<Triggers>();

    }

    private void OnTriggerEnter(Collider other)
    {
        if (weights.Contains(other.gameObject) && !currentWeights.Contains(other.gameObject))
        {
            currentWeights.Add(other.gameObject);
        }
        bool has = true;
        for (int i = 0;i<weights.Count;i++)
        {
            if (!currentWeights.Contains(weights[i]))
            {
                has = false;
                break;
            }
        }
        if (has)
        {
            triggers.CheckInverse(true);
        }
    }
    private void OnTriggerExit(Collider other)
    {
        currentWeights.Remove(other.gameObject);
        
         triggers.CheckInverse(false);
    }
}