Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Mechanisms / HeavyPressurePlate.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class HeavyPressurePlate : MonoBehaviour
  5. {
  6. public List<GameObject> weights = new List<GameObject>();
  7. private List<GameObject> currentWeights = new List<GameObject>();
  8. private Triggers triggers;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. triggers = GetComponent<Triggers>();
  13. }
  14. private void OnTriggerEnter(Collider other)
  15. {
  16. if (weights.Contains(other.gameObject) && !currentWeights.Contains(other.gameObject))
  17. {
  18. currentWeights.Add(other.gameObject);
  19. }
  20. bool has = true;
  21. for (int i = 0;i<weights.Count;i++)
  22. {
  23. if (!currentWeights.Contains(weights[i]))
  24. {
  25. has = false;
  26. break;
  27. }
  28. }
  29. if (has)
  30. {
  31. triggers.CheckInverse(true);
  32. }
  33. }
  34. private void OnTriggerExit(Collider other)
  35. {
  36. currentWeights.Remove(other.gameObject);
  37. triggers.CheckInverse(false);
  38. }
  39. }