Random Prefab Instance Shuffling

Hi, I have a level in which I’ve scattered a several prefab instances of a 3D model around. Then I’ve gone to each one and set different properties like Name, Description and such.

My question is if someone can suggest some tips as to how I can randomly shuffle their properties after each game launch, while keeping their physical positions.

For example, every time you start the game, you see the names on the instances randomly shuffled around. Not looking for code, just general ideas. Thanks.

Nick

I would give each prefab a unique identifier. Let’s say, a public var that is an integer. The 1st one is 0, then 1 etc…

When the program starts, it could have an array of the names that will be used. Shuffle the array so the names are now in random order. Then find each prefab and give it the name in slot x of that array.

You need to create these prefabs in code, as it creates each one set its properties up using random values.

If the position is fixed (as in you have worked out placement already) then you could setup empty gameobjects with names like ph1, ph2, ph3 etc in your scene at these exact locations.

Now, when you create your prefab instants in script you just set its transform to that of your ph gameObject placeholders, in a loop.

This way if you tweak a place holders position then you know that the instant will go to its new pos when you run the game.

Geoff

Thanks for the suggestions guys and for the quick replies! I’ll give it a shot.