Some checks failed
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (push) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Has been cancelled
73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
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<TabletScript>(); // 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);
|
|
}
|
|
}
|
|
|