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

43 lines
1.3 KiB
C#

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