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) { // set puzzleComplete to false var puzzleScript = tabletObject.GetComponent(); // Assuming the script is named "TabletScript" if (puzzleScript == null) { Debug.LogError("TabletScript component not found on tabletObject"); return; } puzzleScript.puzzleComplete = false; 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; } // set the text of the tablet to the current door number, will be last 3 letter of the door name var doorNumber = gameObject.name.Substring(gameObject.name.Length - 3); string doorText = "Target Door: " + doorNumber; puzzleScript.SetTargetText(doorText); // 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); } // Play the door open animation myDoor.Play(animationFile, 0, 0.0f); gameObject.SetActive(false); yield return null; } }