Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Random Background different than previous random background

Discussion in '2D' started by Oliwarrior, May 20, 2020.

  1. Oliwarrior

    Oliwarrior

    Joined:
    Oct 16, 2019
    Posts:
    1
    Hi,

    Im starting in Unity and have set up a script to randomize the background of my levels with an array of background and a sprite renderer. I have 3 total backgrounds. and what Id like to do is still randomize on the first level but on the second level and beyond, I would like it to be random between the two that weren't used on the level just before. Whats the best way to deal with this ?
     
  2. BobNuro

    BobNuro

    Joined:
    Mar 26, 2019
    Posts:
    3
    What about putting them into an array. Randomize an array index, use the image and remove it from the array. For the next level you only have 2 images left in the array, randomize an array index, use the image and remove it from the array. Now it depends on what you want to do but i think after removing the second image, put the first image back into the array and you have 2 images again for the 3rd level. And so on