50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class A9GDrag : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
|
{
|
|
public Text dragTxt;
|
|
public CanvasGroup thisCG;
|
|
public bool answered = false;
|
|
|
|
public A9GAnswerClass thisAnswer;
|
|
public void Awake()
|
|
{
|
|
dragTxt = GetComponentInChildren<Text>();
|
|
}
|
|
|
|
public void SetupThis(A9GAnswerClass receiveAnswer)
|
|
{
|
|
dragTxt = GetComponentInChildren<Text>();
|
|
thisAnswer = receiveAnswer;
|
|
dragTxt.text = thisAnswer.answer;
|
|
answered = false;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData data)
|
|
{
|
|
Vector2 zero = Vector2.zero;
|
|
dragTxt.transform.position = Vector2.SmoothDamp(dragTxt.transform.position, data.position, ref zero, .015f);
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData data)
|
|
{
|
|
dragTxt.transform.parent = GameObject.Find("CanvasA9").transform;
|
|
dragTxt.raycastTarget = false;
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData data)
|
|
{
|
|
dragTxt.raycastTarget = true;
|
|
if (answered)
|
|
{
|
|
dragTxt.text = "";
|
|
}
|
|
dragTxt.transform.parent = transform;
|
|
}
|
|
|
|
}
|