Skip to content

Instantly share code, notes, and snippets.

@tomazsaraiva
Created February 18, 2018 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomazsaraiva/0edd01381b1390f0bce23e841ed75132 to your computer and use it in GitHub Desktop.
Save tomazsaraiva/0edd01381b1390f0bce23e841ed75132 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class Builder : MonoBehaviour
{
[SerializeField]
private GameObject _prefab;
[SerializeField]
private Vector2 _grid;
[SerializeField]
private Vector2 _offset;
private void Start()
{
Build();
}
private void Build()
{
int count = 0;
for (int i = 0; i < _grid.x; i++)
{
for (int j = 0; j < _grid.y; j++)
{
GameObject instance = GameObject.Instantiate(_prefab, transform);
instance.transform.localPosition = new Vector3(_offset.x * i, 0, _offset.y * j);
instance.name = "" + count;
count++;
}
// prepare all gameObject children to static batching
StaticBatchingUtility.Combine(gameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment