using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ChestUI : MonoBehaviour
{
public PlayerHealth healthbar;
public PlayerHealthBar1 health;
private PlayerMovement playermovemnt;
public PlayerMovement2 playermove;
[SerializeField] private ChestManager chestManager;
[SerializeField] private Text multipleText;
[SerializeField] private List butns;
[SerializeField] private Color correctColl, wrongColl, normalColl;
public GameObject unlockmode;
public GameObject overmode;
public GameObject boxs;
public GameObject btns;
public AudioSource opening;
public int Totalwrongs;
public int rights;
public GameObject swapOpen;
public GameObject swapClose;
public GameObject Key;
public static int scorevalue = 0;
public int wrong;
public Text textbox;
public Text wrongbox;
public Text infotext;
private Questionaire questions;
private bool answered;
// Start is called before the first frame update
void Awake()
{
for (int i = 0; i < butns.Count; i++)
{
Button localBtn = butns*;*
localBtn.onClick.AddListener(() => OnClick(localBtn));
}
}
private void Update()
{
infotext.text = rights + “pts to get the key”;
textbox.text = "Score: " + scorevalue;
wrongbox.text = "Wrong: " + wrong + “/” + Totalwrongs;
butns[1].gameObject.SetActive(true);
butns[0].gameObject.SetActive(true);
}
public void SetQuestion(Questionaire question)
{
this.questions = question;
switch (question.questiontypes)
{
case QuestionTypes.TEXT:
break;
}
multipleText.text = question.questionInform;
List answerList = ShuffleList.ShuffleListItems(question.options);
for (int i = 0; i < butns.Count; i++)
{
butns_.GetComponentInChildren().text = answerList*;
butns.name = answerList;_
_butns.image.color = normalColl;
}
answered = false;
}
private void OnClick(Button btn)
{
if (!answered)
{*
bool val = chestManager.Answer(btn.name);_
if (val)
{
scorevalue = scorevalue + 10;
textbox.text = "Score: " + scorevalue;
if (scorevalue == rights)
{
wrong = 0;
scorevalue = 0;
textbox.text = "Score: " + scorevalue;
wrongbox.text = "Wrong: " + wrong + “/” + Totalwrongs;
unlockmode.SetActive(false);
swapOpen.SetActive(true);
swapClose.SetActive(false);
Key.SetActive(true);
overmode.SetActive(false);
opening.Play();
btns.SetActive(true);
boxs.SetActive(true);
}
btn.image.color = correctColl;
}
else
{
btn.image.color = wrongColl;
wrong = wrong + 1;
wrongbox.text = "Wrong: " + wrong + “/” + Totalwrongs;
if (wrong == Totalwrongs)
{
healthbar.currenthealth -= 20;
wrong = 0;
scorevalue = 0;
textbox.text = "Score: " + scorevalue;
wrongbox.text = "Wrong: " + wrong + “/” + Totalwrongs;
overmode.SetActive(false);
}
else if(wrong == Totalwrongs)
{
health.currenthealth -= 20;
wrong = 0;
scorevalue = 0;
textbox.text = "Score: " + scorevalue;
wrongbox.text = "Wrong: " + wrong + “/” + Totalwrongs;
overmode.SetActive(false);
}
}
}
}
public void button1()
{
butns[1].gameObject.SetActive(false);
}
public void button2()
{
butns[0].gameObject.SetActive(false);
}
}
________________________________________________________________________________
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChestManager : MonoBehaviour
{
[SerializeField] private ChestUI chestUI;
[SerializeField]
private List questions;
private int index;
private Questionaire selectedQuestions;
// Start is called before the first frame update
void Start()
{
SelectQuestion();
}
void SelectQuestion()
{
int val = Random.Range(0, questions.Count);
selectedQuestions = questions[val];
index = val;
chestUI.SetQuestion(selectedQuestions);
}
public bool Answer(string answered)
{
bool correctAnswers = false;
if (answered == selectedQuestions.correctAns)
{
correctAnswers = true;
}
else
{
//no
}
Invoke(“SelectQuestion”, 0.4f);
return correctAnswers;
}
}
[System.Serializable]
public class Questionaire
{
public string questionInform;
public List options;
public string correctAns;
public QuestionTypes questiontypes;
}
[System.Serializable]
public enum QuestionTypes
{
TEXT
}