Created
February 18, 2018 00:08
-
-
Save tomazsaraiva/0edd01381b1390f0bce23e841ed75132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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