Advertisement
Guest User

newone

a guest
Feb 22nd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 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. [Tooltip("ENSURE COLORS ARE SET TO 255 ALPHA BEFORE CONFIRMING")]
  30. public Color32[] Colors;
  31. public GameObject PicturePrefab;
  32.  
  33. private void Awake() {
  34.  
  35.  
  36.  
  37. for(int i = 0; i < maxPictures; i++)
  38. {
  39. RandomShape pic = new RandomShape();
  40. pic.BG = bgSprites_[GenerateRandom(bgSprites_.Length)];
  41. pic.FG = fgSprites_[GenerateRandom(fgSprites_.Length)];
  42. pic.Color = Colors[GenerateRandom(Colors.Length)];
  43. Debug.Log(pic.Color);
  44. Pictures.Add(pic);
  45. }
  46.  
  47. PlacePictures();
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55.  
  56. // Start is called before the first frame update
  57. void Start()
  58. {
  59.  
  60.  
  61.  
  62. }
  63.  
  64. int GenerateRandom(int ItemsLength)
  65. {
  66. int randomNumber = Random.Range(0,ItemsLength);
  67. return randomNumber;
  68. }
  69.  
  70.  
  71.  
  72. void PlacePictures()
  73. {
  74. float spacing = 5f;
  75.  
  76. for(int i = 0; i < Pictures.Count-1; i++)
  77. {
  78. // newPicture.AddComponent<SpriteRenderer>().sprite = Pictures[i].BG;
  79. GameObject newPic = Instantiate(PicturePrefab, new Vector3(0,i * spacing,0), Quaternion.identity);
  80. SpriteRenderer newRenderer = newPic.AddComponent(typeof(SpriteRenderer)) as SpriteRenderer;
  81.  
  82. newRenderer.sprite = Pictures[i].BG;
  83. newRenderer.color = Pictures[i].Color;
  84. Debug.Log(Pictures[i].BG);
  85. }
  86. }
  87.  
  88. void ResetGame()
  89. {
  90.  
  91. Pictures.Clear();
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement