- Home /
Question by
unity_F5FF12E67881788F7B75 · Dec 02, 2021 at 03:15 PM ·
newbie
How To Maintain Same Space Between Every Random Shuffle Array Object
How To Maintain Same Space Between Every Random Shuffle Array Object?
public class Grocery : MonoBehaviour
{
public GameObject[] Product ;
public void Start()
{
for (int i = 0; i < Product.Length; i++)
{
int destIndex = Random.Range(0, Product.Length);
GameObject source = Product[i];
GameObject dest = Product[destIndex];
if (source != dest)
{
Vector3 bound = source.transform.position;
source.transform.position = dest.transform.position;
dest.transform.position = bound;
Product[i] = Product[destIndex];
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to add & remove specific gameobject from a list and instantiate them 1 Answer
Trying to use lists to check for available spawn points 2 Answers
Can someone list every possible basic variable? 3 Answers
Force in Circular Motion 1 Answer
a box expands and shrinks after key pressed with a sound? 2 Answers