Advertisement
kadyr

Untitled

Jul 28th, 2021
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class QustionGenerator : MonoBehaviour
  6. {
  7.     [SerializeField] Text _text;
  8.     public TextAsset jsonFile;
  9.     private QuestPack questPack;
  10.     public int currentQuest = -1;
  11.     [SerializeField] List<Transform> listOfQuestionToSpawm;
  12.     [SerializeField] GameObject cube;
  13.     void Start()
  14.     {
  15.         questPack = JsonUtility.FromJson<QuestPack>(jsonFile.text);
  16.         StartCoroutine(CahngeQuestion());
  17.     }
  18.     IEnumerator CahngeQuestion()
  19.     {
  20.         while(QustionsAnswers.gameIsOn == true)
  21.         {
  22.             yield return new WaitForSeconds(8);
  23.             currentQuest++;
  24.             VoidGenerateCubes();
  25.         }
  26.     }
  27.  
  28.     public void VoidGenerateCubes()
  29.     {
  30.         GameObject[] objects = new GameObject[4];
  31.         _text.text = questPack.quests[currentQuest].question;
  32.         for(int i = 0; i<3; i++)
  33.         {
  34.             GameObject newOne = Instantiate(cube, listOfQuestionToSpawm[i].position, Quaternion.identity);
  35.             string text = questPack.quests[currentQuest].wrong_answers[i].ToString();
  36.             objects[i] = newOne;
  37.             newOne.GetComponent<QustController>().SetWrong(text);
  38.         }
  39.         var rObj = Instantiate(cube, listOfQuestionToSpawm[3].position, Quaternion.identity);
  40.         rObj.GetComponent<QustController>().SetRight(questPack.quests[currentQuest].right_answer);
  41.  
  42.         //_text.text = QustionsAnswers.questions.Split('#')[currentQuest];
  43.         //for(int i =0;i<4;i++)
  44.         //{
  45.         //    GameObject newOne =  Instantiate(cube, listOfQuestionToSpawm[i].position, Quaternion.identity);
  46.         //    string text = QustionsAnswers.answers.Split('#')[currentQuest].Split(',')[i];
  47.         //    if (text.Contains("_"))
  48.         //    {
  49.         //        newOne.GetComponent<QustController>().SetRight(text);
  50.         //    }
  51.         //    else
  52.         //    {
  53.         //        newOne.GetComponent<QustController>().SetWrong(text);
  54.         //    }
  55.         //}
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement