58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class LGB_AnswerDragger : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
|
{
|
|
public int order = 0;
|
|
private Text thisText;
|
|
public Transform ttTransform;
|
|
private Transform canvasTranform;
|
|
public bool isAnswered = false;
|
|
private Vector3 zeroV3 = Vector3.zero;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
canvasTranform = GameObject.Find("Canvas - LGB").transform;
|
|
thisText = GetComponentInChildren<Text>();
|
|
ttTransform = thisText.transform;
|
|
}
|
|
|
|
public void SetupThis(int o, string s)
|
|
{
|
|
thisText.text = s;
|
|
order = o;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData data)
|
|
{
|
|
if (!isAnswered)
|
|
{
|
|
ttTransform.position = Vector3.SmoothDamp(ttTransform.position, data.position, ref zeroV3, .05f);
|
|
}
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData data)
|
|
{
|
|
if(!isAnswered)
|
|
{
|
|
thisText.raycastTarget = false;
|
|
ttTransform.parent = canvasTranform;
|
|
}
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData data)
|
|
{
|
|
if (!isAnswered)
|
|
{
|
|
thisText.raycastTarget = true;
|
|
ttTransform.SetParent(transform);
|
|
ttTransform.localPosition = new Vector3(0, 0, 0);
|
|
}
|
|
}
|
|
|
|
}
|