Created
March 10, 2015 11:28
-
-
Save oliverbooth/5f4c2dcf5571f5d10683 to your computer and use it in GitHub Desktop.
Hack for "repeating" ground
This file contains hidden or 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; | |
| 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