Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class GridGenerator : MonoBehaviour
- {
- public GameObject tilePrefab; //gameobject que vai ser usado na grid
- public int numeroDeLinhas;
- public int numeroDeColunas;
- private int quantidade; //quantos elementos terao no total
- public float distancia = 1.0f; //distancia entre cada elemento
- void Start ()
- {
- CreateTiles ();
- }
- void CreateTiles()
- {
- quantidade = numeroDeLinhas * numeroDeColunas;
- float xOffset = 0.0f;
- float yOffset = 0.0f;
- for(int tilesCreated = 0; tilesCreated < quantidade; tilesCreated ++)
- {
- xOffset += distancia;
- if(tilesCreated % numeroDeLinhas == 0)
- {
- yOffset += distancia;
- xOffset = 0;
- }
- Instantiate(tilePrefab, new Vector2 (transform.position.x + xOffset, transform.position.y + yOffset), Quaternion.identity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement