| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class NewQuestionCardController : MonoBehaviour, IPointerClickHandler {
- public GameObject cardBack;
- public GameObject cardFront;
- public GameObject NewQuestionCard;
- bool rotateDone = true;
- [SerializeField] GameObject startParent;
- public void OnPointerClick(PointerEventData eventData) {
- if (cardBack.activeSelf && rotateDone)
- {
- RotateCard();
- }
- }
- public void RotateCard()
- {
- StartCoroutine(Rotate(new Vector3(0, 90f, 0), 0.5f));
- StartCoroutine(secondRotation());
- StartCoroutine(startTimer());
- }
- private IEnumerator startTimer()
- {
- while (!rotateDone) {
- yield return new WaitForSeconds(0.1f);
- }
- GameObject.Find("GameManager").GetComponent<GameManagerScript>().StartTimer();
- }
- public bool getRotationDone() {
- return rotateDone;
- }
- private IEnumerator secondRotation() {
- while (!rotateDone) {
- yield return new WaitForSeconds(0.1f);
- }
- cardBack.SetActive(false);
- cardFront.SetActive(true);
- transform.Rotate(0, 180, 0);
- StartCoroutine(Rotate(new Vector3(0, 90f,0 ), 0.5f));
- }
- private IEnumerator Rotate(Vector3 angle, float duration = 1.0f) {
- rotateDone = false;
- Quaternion from = transform.rotation;
- Quaternion to = Quaternion.Euler(angle) * from;
- float elapsed = 0.0f;
- while (elapsed < duration) {
- transform.rotation = Quaternion.Slerp(from, to, elapsed / duration);
- elapsed += Time.deltaTime;
- yield return null;
- }
- transform.rotation = to;
- rotateDone = true;
- }
- private void ShowBackside() {
- cardBack.SetActive(true);
- cardFront.SetActive(false);
- }
- public void GenerateNewQuestion() {
- resetPosition();
- ShowBackside();
- transform.parent.GetComponent<NewQuestionsPanel>().generateNewQuestion();
- }
- private void resetPosition() {
- transform.SetParent(startParent.transform);
- transform.localPosition = Vector3.zero;
- }
- }
|