- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PressurePlate : MonoBehaviour
- {
- private GameObject objectAbove;
- private bool isPressed = false;
- private Triggers triggers;
-
-
- [SerializeField]
- private List<string> triggerTags;
- [SerializeField]
- private float totalTime;
- private float timer;
-
- private void Start()
- {
- triggers = GetComponent<Triggers>();
- }
- void Update()
- {
- if (timer > 0 && isPressed)
- timer -= Time.deltaTime;
- else
- {
- if (!Physics.Raycast(transform.position, transform.up, 1))
- {
- isPressed = false;
- triggers.CheckInverse(false);
- }
- else
- {
- timer = totalTime;
- }
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- RaycastHit ray;
- timer = totalTime;
- if (Physics.Raycast(transform.position, transform.up,out ray ,1))
- {
-
- foreach (string s in triggerTags)
- {
- if(collision.gameObject.tag == s)
- {
- isPressed = true;
- timer = totalTime;
- triggers.CheckInverse(true);
- }
- }
- }
- }
-
- }
-