Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Puzzles / PressurePlate.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PressurePlate : MonoBehaviour
  5. {
  6. private GameObject objectAbove;
  7. private bool isPressed = false;
  8. private Triggers triggers;
  9. [SerializeField]
  10. private List<string> triggerTags;
  11. [SerializeField]
  12. private float totalTime;
  13. private float timer;
  14. // Update is called once per frame
  15. private void Start()
  16. {
  17. triggers = GetComponent<Triggers>();
  18. }
  19. void Update()
  20. {
  21. if (timer > 0 && isPressed)
  22. timer -= Time.deltaTime;
  23. else
  24. {
  25. if (!Physics.Raycast(transform.position, transform.up, 1))
  26. {
  27. isPressed = false;
  28. triggers.CheckInverse(false);
  29. }
  30. else
  31. {
  32. timer = totalTime;
  33. }
  34. }
  35. }
  36. private void OnCollisionEnter(Collision collision)
  37. {
  38. RaycastHit ray;
  39. timer = totalTime;
  40. if (Physics.Raycast(transform.position, transform.up,out ray ,1))
  41. {
  42. foreach (string s in triggerTags)
  43. {
  44. if(collision.gameObject.tag == s)
  45. {
  46. isPressed = true;
  47. timer = totalTime;
  48. triggers.CheckInverse(true);
  49. }
  50. }
  51. }
  52. }
  53. }