Hey everyone,
I need some help with a C# Script. I will start off by saying I absolutely suck at them. Now that that’s out of the way. I followed a tutorial on scripts for doors, all works like it should. However there’s one script I’d like to change to so that the trigger functions as a button for a VR game.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorInteractPressure : MonoBehaviour
{
[SerializeField] private GameObject doorGameObject;
private IDoor door;
private float timer;
private void Awake()
{
door = doorGameObject.GetComponent<IDoor>();
}
private void Update()
{
if (timer > 0)
{
timer -= Time.deltaTime;
if (timer <= 0f)
{
door.CloseDoor();
}
}
}
private void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.tag == "OpenAuto")
{
// Player entered collider!
door.OpenDoor();
}
}
private void OnTriggerStay(Collider collider)
{
if (collider.gameObject.tag == "OpenAuto")
{
// Player still on top of collider!
timer = 5f;
}
}
}
What I need help with is changing this to a OnTriggerEnter script, that opens door the door, leaves it open, then closes the door once you enter the trigger again.
This would allow for me to use it as a button for a VR game.