- Home /
is there any way to randomzie stripe Selection in 2d
is there a way in c# unity to add stripe on top of each other so i only need to make the main body once and focus only on making the attachments just like the picture but more detailed
[1]: /storage/temp/181704-ex.png
Answer by ShadoX · Jun 05, 2021 at 03:22 PM
Depends on what you mean by randomize, but if you're looking to just have sprites from those you have randomly assigned to the object your screenshots points to, then you could just create an array containing those sprites and pick 1 at random with https://docs.unity3d.com/ScriptReference/Random.Range.html
Just pass in the arrays size to the method, get a random number between 0 and the arrays size - 1 and use that as index to get a sprite from the array via array[index]
or basically something like:
Sprite[] array = new Sprite[3]; //3 being the amount it can fit
array[0] = //first sprite
array[1] = //second sprite
array[2] = //third sprite
//or alternatively assign them in the Unity editor
int randomIndex = Random.Range(0, 3);
Sprite randomSprite = array[randomIndex];
For example.
Your answer
Follow this Question
Related Questions
Recoil in Z axis 0 Answers
Problems setting up a counter for room randomization. 0 Answers
Spawning villages on random gen Terrain 1 Answer
Random AI patrol movement 3 Answers
Creating a Client based server Unity2D 0 Answers