Skip to content

Instantly share code, notes, and snippets.

@oliverbooth
Created March 10, 2015 11:28
Show Gist options
  • Select an option

  • Save oliverbooth/5f4c2dcf5571f5d10683 to your computer and use it in GitHub Desktop.

Select an option

Save oliverbooth/5f4c2dcf5571f5d10683 to your computer and use it in GitHub Desktop.
Hack for "repeating" ground
using UnityEngine;
using System.Collections;
public class RepeatGround : MonoBehaviour
{
public GameObject surfacePrefab;
public GameObject soilPrefab;
public Vector2 widthRange = new Vector2(-100, 100);
public int numLayers = 10;
void Start()
{
int rangeX = (int)widthRange.x;
int rangeY = (int)widthRange.y;
int min = Mathf.Min(rangeX, rangeY);
int max = Mathf.Max(rangeX, rangeY);
GameObject child;
for (int y = 1; y <= numLayers; y++)
{
for (int x = min; x < max; x++)
{
child = Instantiate(y == 1 ? surfacePrefab : soilPrefab) as GameObject;
child.transform.position = new Vector2(0.64f * x, -.64f * y);
child.transform.SetParent(transform);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment