Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Random images

Discussion in 'Scripting' started by Simetris, Jun 14, 2014.

  1. Simetris

    Simetris

    Joined:
    Jun 14, 2014
    Posts:
    6
    Hello! I created a GUI login, and I need put some background images, but one detail ... These images should be random, ie ... will be dozens of images, and when the game is loaded, the engine must choose one randomly and set the background. How can I do?
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    make a list to put all your images in, generate a random number between zero en yourList.Count and use that as the index to get an Image out of the List...?
     
  3. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Look into Random.Range()
     
  4. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    to many people post a question and never coming back... tsss
     
  5. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    make a public array of textures, then assign textureArray[Random.Range(0, textureArray.Length)] to the background.

    True :/