Guest User

Untitled

a guest
Mar 6th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class Grid : MonoBehaviour {
  5.  
  6.     public GameObject[,] gridList = new GameObject[4,4];
  7.     public int GridWidth;
  8.     public int GridHeight;
  9.     public GameObject gridPrefab;
  10.     public GameObject SquarePrefab;
  11.  
  12.     void Start() {
  13.  
  14.         for(int y=0;y<GridHeight;y++) {
  15.             for(int x=0;x<GridWidth;x++) {
  16.  
  17.                 GameObject gridPiece = Instantiate(gridPrefab, new Vector3(x,y,0), Quaternion.identity) as GameObject;
  18.                 gridList[x,y] = gridPiece;
  19.                 gridPiece.transform.parent = this.gameObject.transform;
  20.                 GameObject SquarePiece1 = Instantiate(SquarePrefab, transform.TransformPoint(Vector3.zero), Quaternion.identity) as GameObject;
  21.                 SquarePiece1.transform.parent = gridPiece.transform;
  22.                 SquarePiece1.transform.localPosition = Vector3.zero;
  23.             }
  24.         }
  25.         gameObject.transform.position = new Vector3(-1.5f, 0, 0);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment