Search Unity

Randomize positions of objects only once?

Discussion in 'Scripting' started by JudahMantell, Oct 23, 2018.

  1. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    I apologize if this is the wrong place to post this, but I need a way of spawning objects in a random position each time. But to clarify:
    I want each object to only spawn once in the world. Like, instead of just populating random positions with trees, for example, I have a set number of objects, that each should only spawn a specific number of times per object.

    So I would have a set amount of transforms in specific places, one for each object. But, each time (or with some method call) I want each object from an array of prefabs to spawn on one of those transforms only once (so no double spawning, and no multiples of the same object)

    If someone could help me with this I would really appreciate it!

    Thanks so much!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    You could create a list of all the items available(one entry for each number of available items), then randomly pick an item from the list, remove it from the list and spawn it.
     
  3. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    Thanks for the reply! Lists are something that, while relatively simple, I'm still working on as a programmer.
    Can you give an example?
    Thanks!