Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Surface : MonoBehaviour {
- private static readonly GameObject GameObject1 = new GameObject("Surface");
- private static readonly GameObject GameObject2 = (GameObject) Resources.Load("Ground");
- private static readonly BoxCollider BoxCollider = GameObject1.AddComponent<BoxCollider> ();
- private GameObject obj;
- public void Draw() {
- this.obj = Instantiate (Surface.GameObject2, new Vector3 (this.X, this.Y, this.Z), Quaternion.identity) as GameObject;
- this.Add ();
- }
- private void Add() {
- this.obj.transform.parent = Surface.GameObject1.transform;
- Surface.BoxCollider.size = new Vector3 (this.X, this.Y, this.Z);
- }
- public static Surface Create(int x, int z) {
- var surface = Surface.GameObject1.AddComponent<Surface>();
- surface.x = x;
- surface.y = 0;
- surface.z = z;
- return surface;
- }
- }
- private static readonly Surface[] Surfaces = new Surface[Width * Height];
- for (var z = 0; z < Width; z++) {
- for (var x = 0; x < Height; x++) {
- Surfaces[x + z] = Surface.Create(x, z);
- Surfaces[x + z].Draw();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement