In my scene I have a parent room object. As children to that room object are a bunch of wall objects and a couple connection objects. Each connection object has a reference to the wall objects and two methods. The walls deactivate fine when I call my CloseConnection() method but never reactivate when I call my OpenConnection() method.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Connection classes are used to hold information about where rooms can connect to other rooms
/// Connection classes also hold a list of objects used in opening/closing those connections.
/// </summary>
public class Connection : MonoBehaviour
{
//canOpen will be flagged as true when it's connected to another connection.
public bool canOpen = false;
public bool isOpen = false;
public GameObject[] openObjects;
public GameObject[] closeObjects;
void Start()
{
//Every connection should start closed.
CloseConnection();
}
//TODO: This isn't working. It works if we havent run CloseConnection yet, once we do though it wont work again.
public void OpenConnection()
{
if(canOpen == true)
{
isOpen = true;
foreach(GameObject activatedObject in openObjects)
{
activatedObject.SetActive(true);
//Returns true every time
Debug.Log(activatedObject.activeSelf);
}
foreach(GameObject deactivatedObject in closeObjects)
{
deactivatedObject.SetActive(false);
//returns false every time.
Debug.Log(deactivatedObject.activeSelf);
}
}
}
public void CloseConnection()
{
isOpen = false;
foreach(GameObject deactivatedObject in openObjects)
{
deactivatedObject.SetActive(false);
}
foreach(GameObject activatedObject in closeObjects)
{
activatedObject.SetActive(true);
}
}
}