ZoeAppClass/Assets/Jogos/270/Scripts/A3LA_AnswerDragger.cs

60 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class A3LA_AnswerDragger : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
public A3LA_Answer thisAnswer;
public bool isAnswered = false;
public Transform toMove;
public Text thisText;
private void Awake()
{
thisText = GetComponentInChildren<Text>();
toMove = thisText.transform;
}
public void SetupThis(A3LA_Answer a)
{
if (thisText == null)
{
thisText = GetComponentInChildren<Text>();
}
thisText.text = a.answer;
thisAnswer = a;
isAnswered = false;
toMove.transform.parent = transform;
}
public void OnBeginDrag(PointerEventData data)
{
if (!isAnswered)
{
thisText.raycastTarget = false;
toMove.transform.parent = transform.parent.parent.parent;
}
}
public void OnDrag(PointerEventData data)
{
if (!isAnswered)
{
Vector2 speed = Vector2.zero;
toMove.transform.position = Vector2.SmoothDamp(toMove.transform.position, data.position, ref speed, .01f);
}
}
public void OnEndDrag(PointerEventData data)
{
if (!isAnswered)
{
toMove.transform.parent = transform;
}
}
}