ZoeAppClass/Assets/Jogos/268/Scripts/A3FT_Dragger.cs

57 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class A3FT_Dragger : MonoBehaviour, IBeginDragHandler,IDragHandler,IEndDragHandler
{
private Text thisText;
private A3FT_Answer thisAnswer;
public Transform toMove;
public bool answered = false;
public int index;
private void Awake()
{
thisText = GetComponentInChildren<Text>();
toMove = thisText.transform;
}
public void SetupThis(int rIndex,A3FT_Answer receivedA)
{
thisAnswer = receivedA;
thisText.text = thisAnswer.answer;
index = rIndex;
}
public void OnBeginDrag(PointerEventData data)
{
thisText.raycastTarget = false;
toMove.parent = transform.parent.parent;
}
public void OnDrag(PointerEventData data)
{
Vector2 thisSpeed = Vector2.zero;
toMove.position = Vector2.SmoothDamp(toMove.position, data.position, ref thisSpeed, .01f);
}
public void OnEndDrag(PointerEventData data)
{
if (!answered)
{
toMove.parent = transform;
}
else
{
toMove.localScale = new Vector3(.9f, .9f, .9f);
GetComponent<Image>().raycastTarget = false;
gameObject.SetActive(false);
}
}
}