| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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<Text>();
- }
- public void OnDrag(PointerEventData eventData) {
- NewQuestion.gameObject.transform.position = eventData.position;
- }
- public void OnEndDrag(PointerEventData eventData) {
- itemBeeingDragged = null;
- GetComponent<CanvasGroup>().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<NewQuestionCardController>().GenerateNewQuestion();
- }
- }
- void IBeginDragHandler.OnBeginDrag(PointerEventData eventData) {
- itemBeeingDragged = gameObject;
- GetComponent<CanvasGroup>().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;
- }
- }
- }
|