using System.Collections; using UnityEngine; public class OpenDoor : MonoBehaviour { [SerializeField] private Animator myDoor = null; [SerializeField] private Animator tabletAnimator = null; [SerializeField] private GameObject tabletObject = null; // Reference to the tablet object [SerializeField] public bool openTrigger = false; [SerializeField] private string animationFile = "DoorAnimation.013"; [SerializeField] private bool playTabletAnimation = true; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { Debug.Log("Player has entered the trigger I am: " + gameObject.name); if (!openTrigger) { if (myDoor == null) { Debug.LogError("myDoor is null"); return; } if (tabletObject == null) { Debug.LogError("tabletObject is null"); return; } // open door or play tablet open animation if (playTabletAnimation) { tabletAnimator.Play("Tablet_Open", 0, 0.0f); } else { myDoor.Play(animationFile, 0, 0.0f); } // Start waiting for the puzzle to complete StartCoroutine(WaitForPuzzleCompletion()); } } } private IEnumerator WaitForPuzzleCompletion() { var puzzleScript = tabletObject.GetComponent(); // Assuming the script is named "TabletScript" if (puzzleScript == null) { Debug.LogError("TabletScript component not found on tabletObject"); yield break; } // Wait until the puzzle is complete yield return new WaitUntil(() => puzzleScript.puzzleComplete); Debug.Log("Puzzle completed! Playing animations..."); // Play the tablet close animation if (playTabletAnimation) { tabletAnimator.Play("Tablet_Close", 0, 0.0f); yield return new WaitForSeconds(1f); } // Play the door open animation myDoor.Play(animationFile, 0, 0.0f); gameObject.SetActive(false); } }