Advertisement
Guest User

TestScript

a guest
Feb 22nd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. //Our random shape class/object
  6. public class RandomShape
  7. {
  8. public Sprite BG;
  9. public Sprite FG;
  10. public Color Color;
  11. }
  12.  
  13. //The class to create a random shape/color/fg color/bg color etc...
  14. public class Randomiser : MonoBehaviour
  15. {
  16. [Tooltip ("The random pictures generated from the randomiser..")]
  17. public List<RandomShape> Pictures = new List<RandomShape>();
  18. [Tooltip ("The number of iterations for randomisation.")]
  19. public int maxPictures = 3;
  20. // [Tooltip ("The background sprites")]
  21. // public SpriteRenderer[] bgSprites;
  22. //[Tooltip ("The foreground sprites")]
  23. //public SpriteRenderer[] fgSprites;
  24. // [Tooltip ("The possible colours.")]
  25.  
  26. //Enter the number of bgSprites you want to add in the inspector
  27. public Sprite[] bgSprites_;
  28. public Sprite[] fgSprites_;
  29. public Color[] Colors;
  30. public GameObject PicturePrefab;
  31.  
  32. private void Awake() {
  33.  
  34. for(int i = 0; i < maxPictures; i++)
  35. {
  36. RandomShape pic = new RandomShape();
  37. pic.BG = bgSprites_[GenerateRandom(bgSprites_.Length)];
  38. pic.FG = fgSprites_[GenerateRandom(fgSprites_.Length)];
  39. pic.Color = Colors[GenerateRandom(Colors.Length)];
  40. Debug.Log(pic.Color);
  41. Pictures.Add(pic);
  42. }
  43.  
  44. PlacePictures();
  45.  
  46.  
  47.  
  48.  
  49.  
  50. }
  51.  
  52.  
  53. // Start is called before the first frame update
  54. void Start()
  55. {
  56.  
  57.  
  58.  
  59. }
  60.  
  61. int GenerateRandom(int ItemsLength)
  62. {
  63. int randomNumber = Random.Range(0,ItemsLength);
  64. return randomNumber;
  65. }
  66.  
  67.  
  68.  
  69. void PlacePictures()
  70. {
  71. //float Spacing = 5f;
  72.  
  73. for(int i = 0; i < Pictures.Count-1; i++)
  74. {
  75. // newPicture.AddComponent<SpriteRenderer>().sprite = Pictures[i].BG;
  76. GameObject newPic = Instantiate(PicturePrefab, new Vector3(0,0,0), Quaternion.identity);
  77. newPic.GetComponent<SpriteRenderer>().sprite = Pictures[i].BG;
  78. newPic.GetComponent<SpriteRenderer>().color = Pictures[i].Color;
  79. }
  80. }
  81.  
  82. void ResetGame()
  83. {
  84.  
  85. Pictures.Clear();
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement