65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
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<Animator>();
|
|
if (!isLarge)
|
|
{
|
|
answerTxt = transform.Find("AnswerPart").GetComponentInChildren<Text>();
|
|
questionTxt = transform.Find("QuestionPart").GetComponentInChildren<Text>();
|
|
}
|
|
else
|
|
{
|
|
questionTxt = GetComponentInChildren<Text>();
|
|
}
|
|
}
|
|
|
|
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>())
|
|
{
|
|
RQNA_Dragger temp = data.pointerDrag.GetComponent<RQNA_Dragger>();
|
|
if(index == temp.index)
|
|
{
|
|
temp.isAnswered = true;
|
|
if(nAnswers > 1)
|
|
{
|
|
GameObject newTemp = Instantiate(textToSpawn, transform.Find("QuestionPart").transform, false);
|
|
newTemp.GetComponent<Text>().text = temp.thisAnswer.answerStr;
|
|
}
|
|
else
|
|
{
|
|
anim.SetTrigger("CorrectAnswer");
|
|
answerTxt.text = temp.thisAnswer.answerStr;
|
|
}
|
|
RQNA_Manager.instance.CorrectAnswer();
|
|
|
|
}
|
|
else
|
|
{
|
|
anim.SetTrigger("WrongAnswer");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|