using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class NewQuestionDragController : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler { public static GameObject itemBeeingDragged; public GameObject NewQuestion; public GameObject NewQuestionStartParent; private static Text answerText; private Vector3 startPosition; public Text AnswerText { get => answerText; set => answerText = value; } private void Start() { AnswerText = GameObject.FindGameObjectWithTag("AnswerText").GetComponent(); } public void OnDrag(PointerEventData eventData) { NewQuestion.gameObject.transform.position = eventData.position; } public void OnEndDrag(PointerEventData eventData) { itemBeeingDragged = null; GetComponent().blocksRaycasts = true; // Kontrollera vart man släpper kortet och skicka upp fråga om position ok if (NewQuestionStartParent != transform.parent) { NewQuestion.gameObject.transform.position = startPosition; } if (GetAnswerText().text != "???? - ????") { // Om man svarar nej måste man återställa answerText answerText.text = "???? - ????"; // transform.parent.GetComponent().GenerateNewQuestion(); } } void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) { itemBeeingDragged = gameObject; GetComponent().blocksRaycasts = false; startPosition = NewQuestion.gameObject.transform.position; // Instanciate new object to drag // Save current Position on object (to return to) } public static Text GetAnswerText() { return answerText; } public static void SetAnswerText(string value) { if (NewQuestionDragController.itemBeeingDragged != null) { answerText.text = value; } } }