Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- //Our random shape class/object
- public class RandomShape
- {
- public Sprite BG;
- public Sprite FG;
- public Color Color;
- }
- //The class to create a random shape/color/fg color/bg color etc...
- public class Randomiser : MonoBehaviour
- {
- [Tooltip ("The random pictures generated from the randomiser..")]
- public List<RandomShape> Pictures = new List<RandomShape>();
- [Tooltip ("The number of iterations for randomisation.")]
- public int maxPictures = 3;
- // [Tooltip ("The background sprites")]
- // public SpriteRenderer[] bgSprites;
- //[Tooltip ("The foreground sprites")]
- //public SpriteRenderer[] fgSprites;
- // [Tooltip ("The possible colours.")]
- //Enter the number of bgSprites you want to add in the inspector
- public Sprite[] bgSprites_;
- public Sprite[] fgSprites_;
- public Color[] Colors;
- public GameObject PicturePrefab;
- private void Awake() {
- for(int i = 0; i < maxPictures; i++)
- {
- RandomShape pic = new RandomShape();
- pic.BG = bgSprites_[GenerateRandom(bgSprites_.Length)];
- pic.FG = fgSprites_[GenerateRandom(fgSprites_.Length)];
- pic.Color = Colors[GenerateRandom(Colors.Length)];
- Debug.Log(pic.Color);
- Pictures.Add(pic);
- }
- PlacePictures();
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- int GenerateRandom(int ItemsLength)
- {
- int randomNumber = Random.Range(0,ItemsLength);
- return randomNumber;
- }
- void PlacePictures()
- {
- //float Spacing = 5f;
- for(int i = 0; i < Pictures.Count-1; i++)
- {
- // newPicture.AddComponent<SpriteRenderer>().sprite = Pictures[i].BG;
- GameObject newPic = Instantiate(PicturePrefab, new Vector3(0,0,0), Quaternion.identity);
- newPic.GetComponent<SpriteRenderer>().sprite = Pictures[i].BG;
- newPic.GetComponent<SpriteRenderer>().color = Pictures[i].Color;
- }
- }
- void ResetGame()
- {
- Pictures.Clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement