I am still new to Unity and programming in general. I am having a bit of trouble using code to set a laser door back to active.
I have a laser gameObject sitting beside an “emitter”. Player shoots the “laser” and it deactivates it. The box collider and script are both on the emitter, and only the laserdoor is deactivated. I am using a co-routine as a timer, but its never re-activating the laser. I am hoping someone can find the error in my code. Thank you in advanced.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LDActive : MonoBehaviour
{
public GameObject laserdoor;
public float openTime = 3;
private bool open = false;
void Start()
{
StartCoroutine(DoorOpen());
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Bolt"))
{
laserdoor.gameObject.SetActive(false);
open = true;
}
}
IEnumerator DoorOpen()
{
if (open == true)
{
yield return new WaitForSeconds(openTime);
laserdoor.gameObject.SetActive(true);
open = false;
}
}
}