53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using InfallibleCode;
|
|
|
|
public class LightSwitchesPuzzle : MonoBehaviour
|
|
{
|
|
[SerializeField] private List<NewLightSwitch> lightSwitch;
|
|
[SerializeField] private List<bool> lghtSwitchShouldBeTurnedOn;
|
|
[SerializeField] private UnityEvent afterSolutionEvent;
|
|
[SerializeField] private UnityEvent solutionIsFalseEvent;
|
|
public bool shouldFireFalseSolutionEvent;
|
|
|
|
public void CheckPuzzleCombination()
|
|
{
|
|
//Check if all switches are in the correct position
|
|
bool allLightSwitchesMatch = true;
|
|
if (lightSwitch.Count > 0)
|
|
{
|
|
for (int i = 0; i < lightSwitch.Count; i++)
|
|
{
|
|
if (lightSwitch[i].lightIsOn != lghtSwitchShouldBeTurnedOn[i])
|
|
{
|
|
allLightSwitchesMatch = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If all switches match, fire the afterSolutionEvent
|
|
if (allLightSwitchesMatch)
|
|
{
|
|
afterSolutionEvent.Invoke();
|
|
shouldFireFalseSolutionEvent = true;
|
|
print("light switches match");
|
|
}
|
|
else
|
|
{
|
|
if (shouldFireFalseSolutionEvent)
|
|
{
|
|
// If switches don't match, fire the whenSwitchesDontMatchEvent
|
|
solutionIsFalseEvent.Invoke();
|
|
}
|
|
print("light switches don't match");
|
|
}
|
|
}
|
|
|
|
//public void CheckPuzzleCombinationForOnlyOneLightSwitch()
|
|
//{
|
|
|
|
//}
|
|
}
|