50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class A11G6Dragger : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
|
{
|
|
public Text thisText;
|
|
public A11G6AnswerClass thisAnswer;
|
|
public bool answered = false;
|
|
private Vector3 speed = Vector3.zero;
|
|
|
|
private void Awake()
|
|
{
|
|
thisText = GetComponentInChildren<Text>();
|
|
}
|
|
|
|
public void SetupThis(A11G6AnswerClass rAnswer)
|
|
{
|
|
thisText = GetComponentInChildren<Text>();
|
|
thisAnswer = rAnswer;
|
|
thisText.text = thisAnswer.answerText;
|
|
answered = false;
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData data)
|
|
{
|
|
thisText.raycastTarget = false;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData data)
|
|
{
|
|
thisText.transform.position = Vector3.SmoothDamp(thisText.transform.position, data.position, ref speed, .015f);
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData data)
|
|
{
|
|
if (answered)
|
|
{
|
|
thisText.text = "Correct!";
|
|
}
|
|
else
|
|
{
|
|
thisText.raycastTarget = true;
|
|
}
|
|
thisText.transform.SetParent(transform);
|
|
}
|
|
}
|