Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public class Surface : MonoBehaviour {
  2.  
  3. private static readonly GameObject GameObject1 = new GameObject("Surface");
  4.  
  5. private static readonly GameObject GameObject2 = (GameObject) Resources.Load("Ground");
  6.  
  7. private static readonly BoxCollider BoxCollider = GameObject1.AddComponent<BoxCollider> ();
  8.  
  9. private GameObject obj;
  10.  
  11. public void Draw() {
  12. this.obj = Instantiate (Surface.GameObject2, new Vector3 (this.X, this.Y, this.Z), Quaternion.identity) as GameObject;
  13. this.Add ();
  14. }
  15.  
  16. private void Add() {
  17. this.obj.transform.parent = Surface.GameObject1.transform;
  18.  
  19. Surface.BoxCollider.size = new Vector3 (this.X, this.Y, this.Z);
  20. }
  21.  
  22. public static Surface Create(int x, int z) {
  23. var surface = Surface.GameObject1.AddComponent<Surface>();
  24. surface.x = x;
  25. surface.y = 0;
  26. surface.z = z;
  27.  
  28. return surface;
  29. }
  30. }
  31.  
  32. private static readonly Surface[] Surfaces = new Surface[Width * Height];
  33.  
  34. for (var z = 0; z < Width; z++) {
  35. for (var x = 0; x < Height; x++) {
  36. Surfaces[x + z] = Surface.Create(x, z);
  37. Surfaces[x + z].Draw();
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement