using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class RQNA_Dropper : MonoBehaviour, IDropHandler { private Text answerTxt, questionTxt; public int index = 0; public int nAnswers = 0; public bool isLarge = false; public GameObject textToSpawn; private Animator anim; public void Awake() { anim = GetComponent(); if (!isLarge) { answerTxt = transform.Find("AnswerPart").GetComponentInChildren(); questionTxt = transform.Find("QuestionPart").GetComponentInChildren(); } else { questionTxt = GetComponentInChildren(); } } public void Setup(string quest, int indx, int nAnswer = 1) { questionTxt.text = quest; nAnswers = nAnswer; index = indx; } public void OnDrop(PointerEventData data) { if (data.pointerDrag.GetComponent()) { RQNA_Dragger temp = data.pointerDrag.GetComponent(); if(index == temp.index) { temp.isAnswered = true; if(nAnswers > 1) { GameObject newTemp = Instantiate(textToSpawn, transform.Find("QuestionPart").transform, false); newTemp.GetComponent().text = temp.thisAnswer.answerStr; } else { anim.SetTrigger("CorrectAnswer"); answerTxt.text = temp.thisAnswer.answerStr; } RQNA_Manager.instance.CorrectAnswer(); } else { anim.SetTrigger("WrongAnswer"); } } } }