Files
2025-05-29 22:31:40 +03:00

45 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using InfallibleCode;
public class WindowPuzzle : MonoBehaviour
{
[SerializeField] private List<DraggableWindow> window;
[SerializeField] private List<bool> windowShouldBeOpen;
[SerializeField] private UnityEvent afterSolutionEvent;
[SerializeField] private UnityEvent solutionIsFalseEvent;
public bool shouldFireFalseSolutionEvent;
public void CheckPuzzleCombination()
{
// Check if all switches are in the correct position
bool allWindowsMatch = true;
for (int i = 0; i < window.Count; i++)
{
if (window[i].WindowIsOpen != windowShouldBeOpen[i])
{
allWindowsMatch = false;
}
}
// If all switches match, fire the afterSolutionEvent
if (allWindowsMatch)
{
afterSolutionEvent.Invoke();
shouldFireFalseSolutionEvent = true;
print("Windows match");
}
else
{
if (shouldFireFalseSolutionEvent)
{
// If switches don't match, fire the whenSwitchesDontMatchEvent
solutionIsFalseEvent.Invoke();
}
print("Windows don't match");
}
}
}