Hi, so my game features rooms that instantiate after the player opens a door. I got the player to open the door and have the following room instantiate just fine. The problem is that the script that spawns more rooms no longer works within the instantiated new room, so when I open a door, nothing happens.
I suspect that because I’m telling it to look for a value in a script within a gameObject as a trigger, it’s reading that as true since the previous door was opened. And it finds the status of the script of the previous use of that script in the first prefab and not in its own local one. I also suspect this is due to naming conventions I used, since the only change in the names of the instantiated room is “Name of Prefab (Clone)”. I don’t know how to detect this via a function instead of just hardcoding it like I have here.
using UnityEngine;
using System.Collections;
public class RoomSpawnL : MonoBehaviour
{
public Transform Room_Prefab;
GameObject DoorOpen; //Create a Game Object variable called Door_R
OpenableDoor door; //Door is an OpenableDoor variable type based on the existing OpenableDoor script?
public int RoomNum = 10;
// Use this for initialization
void Start ()
{
Debug.Log("START --> " + this);
DoorOpen = GameObject.Find ("Door_L"); //Unity looks for a GameObject called "Door_R" in my hierarchy and makes the Door_R variable equal that.
}
// Update is called once per frame
void Update ()
{
door = DoorOpen.GetComponent<OpenableDoor> (); //Door Variable = *Name of the GameObject in the hierarchy or the GameObject/Variable with that data*.GetComponent<*Script on said object I want to access*>()
// for (int i = 0; i < RoomNum; i++) {
if (door.open == true) {
if(!door.spawnOnce) {
door.spawnOnce = true;
Instantiate (Room_Prefab, transform.position, transform.localRotation);
Debug.Log ("New room!");
}
} else if (door.opening == false) {
Debug.Log ("No new room... :( ");
}
//}
}
}
I’m not very sure what exactly I should be doing here to fix this problem. Do I make an array of naming conventions? Is there method or function I can use to manage this?