49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class A13DDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDragHandler
|
|
{
|
|
public bool isAnswered;
|
|
private Text thisText;
|
|
public A13DAnswerClass thisAnswer;
|
|
|
|
|
|
public void SetupThis(A13DAnswerClass rAnswer)
|
|
{
|
|
thisAnswer = rAnswer;
|
|
if (!thisText)
|
|
{
|
|
thisText = GetComponentInChildren<Text>();
|
|
}
|
|
thisText.text = thisAnswer.answerStr;
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData data)
|
|
{
|
|
thisText.raycastTarget = false;
|
|
thisText.transform.parent = GameObject.Find("Game Canvas").transform;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData data)
|
|
{
|
|
Vector3 poop = Vector3.zero;
|
|
thisText.transform.position = Vector3.SmoothDamp(thisText.transform.position, data.position, ref poop, .005f);
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData data)
|
|
{
|
|
thisText.transform.parent = transform;
|
|
if (!isAnswered)
|
|
{
|
|
thisText.raycastTarget = true;
|
|
}
|
|
else
|
|
{
|
|
thisText.text = "";
|
|
}
|
|
}
|
|
}
|