Skip to content

Instantly share code, notes, and snippets.

@Drenerdo
Created May 1, 2019 01:46
Show Gist options
  • Save Drenerdo/eb2f439febf06246a580c4e517321ccc to your computer and use it in GitHub Desktop.
Save Drenerdo/eb2f439febf06246a580c4e517321ccc to your computer and use it in GitHub Desktop.
Combinations
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;
public List<GameObject> combo6;
public List<GameObject> combo7;
public List<GameObject> combo8;
List<List<GameObject>> combinations;
public List<GameObject> currentlyActive;
public DialogueManager dialogue;
// Session Buttons
public GameObject SessionButton;
// List of button images
TPO_Event_Trigger tpo_eventTrigger;
public Button[] tpo_event_trigger;
void Start()
{
SessionButton.SetActive(false);
//buttonImage = GetComponentsInChildren<Image>(true);
tpo_eventTrigger = GetComponentInChildren<TPO_Event_Trigger>();
//tpo_eventTrigger.tpo_rend.enabled = true;
combinations = new List<List<GameObject>>()
{
combo1,
combo2,
combo3,
combo4,
combo5,
combo6,
combo7,
combo8
};
}
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;
//dialogue.dialogue.text = dialogue.dialogue23;
CorrectCombinationMessage();
SessionButton.SetActive(true);
tpo_eventTrigger.tpo_arrow_UI.Disable_Arrow();
tpo_eventTrigger.colliderController.enabled = false;
}
else if (currentlyActive.Count > combination.Count && matches != combination.Count)
{
print("Doesn't match one of the combinations");
NoMatchfound = true;
dialogue.dialogue.text = dialogue.dialogue24;
ResetButtonSelection();
matches = 0;
}
}
//if (foundMatch)
//{
// print("Found Match");
// dialogue.dialogue.text = dialogue.dialogue23;
// SessionButton.SetActive(true);
// tpo_eventTrigger.tpo_arrow_UI.Disable_Arrow();
// tpo_eventTrigger.colliderController.enabled = false;
//}
//else
//{
// //dialogue.dialogue.text = dialogue.dialogue24;
//}
}
void CorrectCombinationMessage()
{
StartCoroutine(SuccessMessage());
}
IEnumerator SuccessMessage()
{
yield return new WaitForSeconds(1);
dialogue.dialogue.text = dialogue.dialogue22;
yield return new WaitForSeconds(3);
dialogue.dialogue.text = dialogue.dialogue23;
}
void ResetButtonSelection()
{
currentlyActive.Clear();
tpo_event_trigger = GetComponentsInChildren<Button>();
foreach (Button g in tpo_event_trigger)
{
g.GetComponent<Image>().enabled = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment