49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PressurePlateScript : MonoBehaviour
|
|
{
|
|
private float? triggered = null;
|
|
[SerializeField] private float doorDelay = 2.0f;
|
|
private bool opened = false;
|
|
|
|
[SerializeField] private Animator pPlateAnim = null;
|
|
[SerializeField] private Animator doorAnim = null;
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.CompareTag("Player") && !opened)
|
|
{
|
|
//pressure plate down and start trigger time
|
|
pPlateAnim.Play("PPdown", 0, 0f);
|
|
triggered = Time.time;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if(other.CompareTag("Player"))
|
|
{
|
|
if(triggered!=null && !opened)
|
|
{
|
|
triggered = null;
|
|
pPlateAnim.Play("PPup", 0, 0f);
|
|
//reset platform position
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var timepassed = Time.time - triggered;
|
|
|
|
if(timepassed > doorDelay && !opened)
|
|
{
|
|
//move door
|
|
doorAnim.Play("DoorUp", 0, 0f);
|
|
opened = true;
|
|
|
|
}
|
|
}
|
|
} |