Advertisement
NomadicWarrior

Puzzle

Jul 7th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. // image script - start //
  2.  
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. [System.Serializable]
  8. public class PhotoData
  9. {
  10. public Object[] photo_4 = new Object[4];
  11.  
  12. }
  13.  
  14. // image script - end //
  15.  
  16. // Image holder script-start //
  17.  
  18. using System.Collections;
  19. using System.Collections.Generic;
  20. using UnityEngine;
  21.  
  22. [System.Serializable]
  23. public class TitleData
  24. {
  25. public int pointsAddedForPuzzle;
  26. public string photoTitle;
  27. public PhotoData[] photos;
  28. }
  29.  
  30. // Image holder script-end //
  31.  
  32. // All data script - start //
  33.  
  34. using System.Collections;
  35. using System.Collections.Generic;
  36. using UnityEngine;
  37. using System.IO;
  38.  
  39. public class PuzzleController : MonoBehaviour {
  40.  
  41. public TitleData[] allTitles;
  42.  
  43. void Start ()
  44. {
  45. DontDestroyOnLoad(gameObject);
  46.  
  47. for (int i = 0; i < allTitles.Length; i++)
  48. {
  49. for (int t = 0; t < allTitles[i].photos.Length; t++)
  50. {
  51.  
  52. int newIndex = Random.Range(0, allTitles[i].photos[t].photo_4.Length);
  53.  
  54. int currentIndex = newIndex;
  55. for (int p = 0; p < allTitles[i].photos[t].photo_4.Length; p++)
  56. {
  57. //allTitles[i].photos[t].photo_4[p] = allTitles[i].photos[t].photo_4[currentIndex];
  58. }
  59. }
  60. }
  61. }
  62.  
  63. public TitleData GetCurrentTitle ()
  64. {
  65. return allTitles[0];
  66. }
  67.  
  68. }
  69.  
  70. // All data script - end //
  71.  
  72.  
  73. // Insert - image - start // From data to UI Image
  74.  
  75. using System.Collections;
  76. using System.Collections.Generic;
  77. using UnityEngine;
  78. using UnityEngine.UI;
  79.  
  80. public class InsertImage : MonoBehaviour {
  81.  
  82. public PuzzleController puzzleController;
  83.  
  84. public Image[] childSprites;
  85.  
  86. int randomLevel;
  87.  
  88. private void Awake()
  89. {
  90. // Find puzzles
  91. puzzleController = FindObjectOfType<PuzzleController>();
  92. }
  93.  
  94. private void Start()
  95. {
  96. // Randomize puzzle
  97. randomLevel = Random.Range(0, 2);
  98.  
  99. // if easy level
  100. for (int i = 0; i < childSprites.Length; i++)
  101. {
  102. for (int a = 0; a < puzzleController.allTitles.Length; a++)
  103. {
  104. for (int p = 0; p < puzzleController.allTitles[a].photos.Length; p++)
  105. {
  106. int newIndex = Random.Range(0, puzzleController.allTitles[a].photos[p].photo_4.Length);
  107.  
  108. childSprites[i].sprite = (Sprite)puzzleController.allTitles[a].photos[randomLevel].photo_4[newIndex];
  109. }
  110. }
  111. }
  112. }
  113.  
  114. public void DeleteLevel ()
  115. {
  116. // Delete already passed level
  117. }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement