how can i shuffle cubes

i have 15 cubes and 1 empty gameobject,i want to shuffle them so they change their position on start of the game.
i tried this snippet but nothing is happening.

``````    var cube1 : GameObject;
var cube2 : GameObject;
var cube3 : GameObject;
var cube4 : GameObject;
var cube5 : GameObject;
var cube6 : GameObject;
var cube7 : GameObject;
var cube8 : GameObject;
var cube9 : GameObject;
var cube10 : GameObject;
var cube11 : GameObject;
var cube12 : GameObject;
var cube13 : GameObject;
var cube14 : GameObject;
var cube15 : GameObject;
var slot : Transform;
//var cubes: Vector3[]  = new Vector3[16];
//var index : int = 0;

var cubes: Transform[];

function Start ()
{
ChangePosition();
// OnMouseUp();
}
function ChangePosition()
{

//  for (var i = 0; i < cubes.Length; i++) {
//  var j = Random.Range(0, cubes.Length);
//  var tmp = cubes*.position;*
``````

// cubes*.position = cubes[j].position;*
// cubes[j]. position = tmp;
cube1.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube2.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube3.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube4.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube5.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube6.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube7.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube8.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube9.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube10.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube11.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube12.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube13.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube14.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

cube15.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

slot.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);

// }
}

function OnMouseUp() {
//if(Vector3.Distance(transform.position,slot.position)==1
if(Vector3.Distance(transform.position,slot.position)==1)
{
xtemp = transform.position.x;
ytemp = transform.position.y;
transform.position.x=slot.position.x;
transform.position.y=slot.position.y;
slot.position.x = xtemp;
slot.position.y = ytemp;

}
}

I’m going to assume you are going to initialize the ‘cubes’ array through drag and drop in the inspector. And that array is initialized with game object from the hierarchy.

``````#pragma strict

var cubes: Transform[];  // Initialized in the Inspector

function Start () {
ChangePosition();
}

function ChangePosition() {
for (var i = 0; i < cubes.Length; i++) {
var j = Random.Range(0, cubes.Length);
var tmp = cubes*.position;*
``````

_ cubes*.position = cubes[j].position;_
_
cubes[j]. position = tmp;_
_
}_
_
}*_

Lets give clear idea to you.

``````Vector3 shuffleArray = new Vector3[cubes.length];
``````

Here, shuffleArray holds position of each cube means initial position of each cube.
Then we interchange position of this shuffleArray means using shuffle algorithm we perform this task.

Now we have new position array ready. We apply it to cubes.

``````for(int i=0;i<shuffleArray.Length;i++)
cubes_.transform.position = shuffleArray*;*_
``````

Now each cube has new position because of shuffling.