- Home /
When I deleted an UI obj. in a cell, I want an empty cell. How can I do this?
In the Unity Canvas Panel, grid layout group, when I deleted an UI obj. in a cell manually, I want an empty cell but the next one cell's object is coming instead of the deleted one.
How can I solve this? Here is my codes :
public class DynamicGrid : MonoBehaviour {
public int col, row;
public Image[] prefabs = new Image[6];
private Image[,] image;
private int[,] index;
// Use this for initialization
void Start () {
image = new Image[row,col] ; //get the number of every jewels to compare
index = new int[row,col] ;
RectTransform parent = gameObject.GetComponent<RectTransform> ();
GridLayoutGroup grid = gameObject.GetComponent<GridLayoutGroup> ();
grid.cellSize = new Vector2 (parent.rect.width / col, parent.rect.height / row); //grid cell size (ex: 4x4 - 3x5 etc.)
for (int i = 0; i < row; i++) { //fill the rows
for (int j = 0; j < col; j++) { //fill the columns
int num = UnityEngine.Random.Range (0, prefabs.Length); //select a random number (from 0 to 6 each numbers for each different jewel images)
image[i,j] = (Image)Instantiate (prefabs[num]); //create the randomly seleceted image
image[i,j].transform.SetParent (transform, false);
index[i,j] = image[i,j].gameObject.transform.GetSiblingIndex ();
}
}
}
Comment