Hello,
I have a script that enables/disables rooms. When the room is enabled animation plays and the door of the prefab opens, using this script:
private Animator animator;
bool doorOpen = true;
private void Awake()
{
animator = GetComponent<Animator> ();
}
public void OpenDoor()
{
StartCoroutine(Open());
}
IEnumerator Open()
{
if (doorOpen)
{
yield return new WaitUntil(() => animator.isInitialized);
animator.SetBool("Open", true);
}
}
The script is called from another script that manages the room changing, when the “OpenDoor()” function is called the first time, the animation plays, however when the function is being called again in the next rooms, it doesn’t execute it.
I’ve debugged each method and the problem is that the Coroutine won’t start again, the “OpenDoor()” get’s called but won’t go to the coroutine “Open()”.
EDIT: quick update it will show an error
Coroutine couldn’t be started because the the game object ‘Elevator’ is inactive!
But why? I have an instance of this prefab at each room, so why can’t it realize that when one instance in disabled the other is enabled and move on… why is it stuck on the disabled instance?