# Positioning problems with random rooms

Im trying to create a floor out of 4 rooms in one line. Basically I just have to instantiate them and set their position. Im doing this in a for-loop. When I only use one prefab (no random necessary) i can create the 4 rooms and everything works. But when i try to create 4 random rooms out of 3 prefabs the positioning is not right. I mean sometimes it is correct but sometimes one of the rooms has the same position as another room. I cant understand that because I multiply my x-coordinate with the variable from the loop (i), that would mean the variable would get used sometimes twice. I think there is something with my Random.Range command because its only not working when I try to make it random. Here is my code for this:

``````	public int[] Room = new int[5];

public new Vector3 pos;
int xpos = 54;
int zpos = 0;

public GameObject[] R = new GameObject[3];

// Use this for initialization
void Start () {

for(int i = 1 ; i < 5 ; i++ ){

Room  *= Random.Range (0, 3);*
``````

_ xpos = 54*i;_

_ if (R [Room*].GetComponents ().Length < 1) { //Add MeshCollider if not already added*_
_ R [Room*].AddComponent ();
}
Instantiate (R [Room]); //create Room*

R [Room*].name = āā + xpos; //rename Room*_

* pos = new Vector3 (xpos, 0, zpos);*
_ R [Room*].transform.position = pos; //position Room*_

* }*

* }*
This is the whole script. I have added three prefabs to the GameObject array. I multiply āiā with 54 because 54 is the size of my room.

`R` is your array of Prefabs, right? Then `R [Room_]` is your prefab object, not your instance so changing the name and position will change the prefabs properties and not the ones of your actual room in the scene._
Use `room = Instantiate (R [Room_]) as GameObject;` and then `room.transform.position`, or `Instantiate (R [Room*],pos,Quaternion.identity) as GameObject;`instead.*_