Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GameController : MonoBehaviour {
  5.  
  6.     public int width = 10;
  7.     public int height = 10;
  8.  
  9.     private GameObject[,] grid;
  10.     public GameObject block;
  11.     public float blockSize;
  12.  
  13.     // Use this for initialization
  14.     void Start () {
  15.        
  16.         grid = new GameObject[width, height];
  17.         var gridWidth = width * blockSize;
  18.         var gridHeight = height * blockSize;
  19.         var beginX = -gridWidth / 2;
  20.         var beginY = -gridHeight / 2;
  21.         for (int i = 0; i < width; i++)
  22.         {
  23.             for (int j = 0; j < height; j++)
  24.             {
  25.                 GameObject temp = (GameObject)Instantiate(block, new Vector3(beginX + i * blockSize, beginY + j * blockSize, 0), Quaternion.identity);
  26.                 temp.transform.localScale = new Vector3(1, 1, 1);
  27.                 grid[i, j] = temp;
  28.  
  29.  
  30.             }
  31.         }
  32.     }
  33.    
  34.     // Update is called once per frame
  35.     void Update () {
  36.    
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement