Advertisement
dantepw

Grid Generator Unity

Dec 2nd, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GridGenerator : MonoBehaviour
  5. {
  6.     public GameObject tilePrefab; //gameobject que vai ser usado na grid
  7.     public int numeroDeLinhas;
  8.     public int numeroDeColunas;
  9.     private int quantidade; //quantos elementos terao no total
  10.     public float distancia = 1.0f; //distancia entre cada elemento
  11.    
  12.  
  13.     void Start ()
  14.     {
  15.         CreateTiles ();
  16.     }
  17.  
  18.     void CreateTiles()
  19.     {
  20.         quantidade = numeroDeLinhas * numeroDeColunas;
  21.  
  22.         float xOffset = 0.0f;
  23.         float yOffset = 0.0f;
  24.        
  25.         for(int tilesCreated = 0; tilesCreated < quantidade; tilesCreated ++)
  26.         {
  27.  
  28.             xOffset += distancia;
  29.  
  30.             if(tilesCreated % numeroDeLinhas == 0)
  31.             {
  32.                 yOffset += distancia;
  33.                 xOffset = 0;
  34.             }
  35.  
  36.             Instantiate(tilePrefab, new Vector2 (transform.position.x + xOffset, transform.position.y + yOffset), Quaternion.identity);
  37.  
  38.         }
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement