Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7.  
  8. public class simple_game : MonoBehaviour
  9. {
  10. public Text text; // поле вывода
  11. private List<string> list;
  12. int r;//номер факта
  13. public GameObject next;//кнопка след. факта
  14. public void Start()
  15. {
  16.  
  17. list = File.ReadAllLines(Application.dataPath + "/resources/simple_q.txt").ToList();
  18. // Debug.Log($"В файле найдено строк {list.Count} строк");
  19. GenerateFacts();
  20. }
  21. public void GenerateFacts()
  22. {
  23. if (list.Count > 0)//Если в листе есть факты то...
  24. {
  25. r = Random.Range(0, list.Count);// случайное число от 0 до кол-ва фактов
  26. text.text = list[r];
  27. list.RemoveAt(r);//удаляем факт
  28. //Debug.Log($"вы нажали на кнопку, осталось {list.Count} фактов");
  29. }
  30. else
  31. {
  32. next.SetActive(false);
  33. text.text = "Пока что на этом всё";
  34. //Debug.Log("факты закончились, кнопка выключена");
  35. }
  36.  
  37. }
  38. public void close()// кнопка выход в меню
  39. {
  40. SceneManager.LoadScene("categories");
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement