Skip to content

Instantly share code, notes, and snippets.

@Drenerdo
Last active April 18, 2019 16:41
Show Gist options
  • Save Drenerdo/c45b76d424fb870e1752440dcaa05437 to your computer and use it in GitHub Desktop.
Save Drenerdo/c45b76d424fb870e1752440dcaa05437 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CombinationCheck : MonoBehaviour
{
public List<GameObject> combo1;
public List<GameObject> combo2;
public List<GameObject> combo3;
public List<GameObject> combo4;
public List<GameObject> combo5;
List<List<GameObject>> combinations;
public List<GameObject> currentlyActive;
void Start()
{
combinations = new List<List<GameObject>>()
{
combo1,
combo2,
combo3,
combo4,
combo5
};
}
public void ButtonPressed(GameObject myButton)
{
if(!currentlyActive.Contains(myButton))
{
currentlyActive.Add(myButton);
}
else if (currentlyActive.Contains(myButton))
{
currentlyActive.Remove(myButton);
}
bool foundMatch = false;
bool NoMatchfound = false;
foreach(List<GameObject> combination in combinations)
{
int matches = 0;
foreach (GameObject chosenButton in currentlyActive)
{
if (combination.Contains(chosenButton))
{
matches++;
}
}
if (currentlyActive.Count == combination.Count && matches == combination.Count)
{
foundMatch = true;
//tpo_eventTrigger.tpo_rend.enabled = true;
}
else
{
print("Doesn't match one of the combinations");
NoMatchfound = true;
}
}
if (foundMatch)
{
print("Found Match");
// Returning a success message for the user to see
}
else
{
// Returning an error message... Letting the user know that the combination is wrong
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment