Hi, i just start programming for unity 3d (3-4 days from now %) ) and make a simple script to make grid from cubes (you can choose how many cells you want to make) and its working… but i think its to complicated what i can change for simplicity? And one more question… how to sort this list? Thanks guyz!
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CreateAGridFromCube : MonoBehaviour {
public GameObject cube;
public int horCells;
public int verCells;
public List<GameObject> cellsList = new List<GameObject>();
// Use this for initialization
void Start () {
cellsList.Add (cube);
MakeGrid (horCells,verCells);
}
void MakeGrid(int hor, int vert){
for (int x = 0; (x + 1) < hor; x++) {
GameObject clone = Instantiate (cube);
clone.transform.position = new Vector3(clone.transform.position.x+1,clone.transform.position.y,clone.transform.position.z);
clone.name = "1x" + (x + 2);
for (int y = 0; (y+1) < vert; y++) {
GameObject cloneV = Instantiate (cube);
cloneV.transform.position = new Vector3(cloneV.transform.position.x,cloneV.transform.position.y-1,cloneV.transform.position.z);
cloneV.name = (y + 2)+ "x" + (x + 1);
cellsList.Add (cloneV);
cube = cloneV;
}
cellsList.Add (clone);
cube = clone;
}
int z = cellsList.Count - 1;
GameObject fuckingLastClones = cellsList [z];
for (int i = 0; (i+1) < vert; i++) {
GameObject LastLastClones = Instantiate (fuckingLastClones);
LastLastClones.transform.position = new Vector3(LastLastClones.transform.position.x,LastLastClones.transform.position.y-1,LastLastClones.transform.position.z);
LastLastClones.name = (i+2) + "x" + hor;
cellsList.Add (LastLastClones);
fuckingLastClones = LastLastClones;
}
}
}