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; [SerializeField] private GameObject crosshair = null; // enable and disable crosshair when player in tablet trigger [SerializeField] private StarterAssets.StarterAssetsInputs mouseLook = null; [SerializeField] private ControlScript controlScript = null; [SerializeField] private AudioClip victorySound = null; // set number of bombs and grid size [SerializeField] private int bombs = 9; [SerializeField] private int gridSize = 11; [SerializeField] private int timeLimitSeconds = 10; 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; // disable crosshair crosshair.SetActive(false); // set player motion to 0 mouseLook.move = Vector2.zero; mouseLook.look = Vector2.zero; // play the tablet open animation tabletAnimator.Play("Tablet_Open", 0, 0.0f); if (mouseLook != null) { mouseLook.cursorInputForLook = false; } // unlock cursor Cursor.lockState = CursorLockMode.None; Cursor.visible = true; // set state to playing on control script for mines, reset the game if (controlScript != null) { controlScript.GridSizeX = gridSize; controlScript.GridSizeY = gridSize; controlScript.TotalMines = bombs; controlScript.timeLimitSeconds = timeLimitSeconds; controlScript.Restart(); } } 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.SetDoorTargetText(doorText); // convert time limit to minutes:seconds var doorTimeLimit = "Time Limit: " + timeLimitSeconds / 60 + ":" + timeLimitSeconds % 60 + " "; puzzleScript.SetDoorTimeLimitText(doorTimeLimit); // Wait until controlscript is in state Win yield return new WaitUntil(() => controlScript.GameState == ControlScript.EGameState.Win); // SoundFXManager.instance.PlaySound(victorySound, transform, 1.0f); // wait 5 seconds yield return new WaitForSeconds(1.0f); // reset the game state controlScript.Restart(); Debug.Log("Puzzle completed! Playing animations..."); // Play the tablet close animation if (playTabletAnimation) { tabletAnimator.Play("Tablet_Close", 0, 0.0f); // enable crosshair crosshair.SetActive(true); // lock cursor Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; // var mouseLook = GetComponent(); if (mouseLook != null) { mouseLook.cursorInputForLook = true; } } // Play the door open animation myDoor.Play(animationFile, 0, 0.0f); gameObject.SetActive(false); yield return null; } }