79 lines
1.9 KiB
C#
79 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class UntangleDrag : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler, IPointerClickHandler
|
|
{
|
|
public Text thisTxt;
|
|
public Transform canvasParent;
|
|
public UntangleQuestion.UntangleAnswer thisAnswer;
|
|
public bool isAnswered = false;
|
|
private int gameMode = 0;
|
|
|
|
public void Awake()
|
|
{
|
|
canvasParent = GameObject.Find("GameCanvas").transform;
|
|
}
|
|
public void SetupAnswer(UntangleQuestion.UntangleAnswer a, int gM = 0)
|
|
{
|
|
thisAnswer = a;
|
|
gameMode = gM;
|
|
thisTxt.text = thisAnswer.answer;
|
|
thisTxt.raycastTarget = true;
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData data)
|
|
{
|
|
if (gameMode == 1)
|
|
{
|
|
if (UntangleDrop.instance.TestAnswer(this))
|
|
{
|
|
thisTxt.text = "";
|
|
thisTxt.raycastTarget = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData data)
|
|
{
|
|
if (gameMode == 0)
|
|
{
|
|
if (!isAnswered)
|
|
{
|
|
thisTxt.raycastTarget = false;
|
|
thisTxt.transform.parent = canvasParent;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnDrag(PointerEventData data)
|
|
{
|
|
if (gameMode == 0)
|
|
{
|
|
if (!isAnswered)
|
|
{
|
|
thisTxt.transform.position = Vector3.Lerp(thisTxt.transform.position, data.position, 0.15f);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData data)
|
|
{
|
|
if (gameMode == 0)
|
|
{
|
|
if (isAnswered)
|
|
{
|
|
thisTxt.text = "";
|
|
}
|
|
else
|
|
{
|
|
thisTxt.raycastTarget = true;
|
|
}
|
|
thisTxt.transform.parent = transform;
|
|
}
|
|
|
|
}
|
|
}
|