Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- enum FieldType {
- Cube,
- Recursive,
- Empty
- }
- class Level {
- int depth;
- int recLimit;
- public static float sideSize = 10.0f;
- Level[,,] lowerLevel = new Level[3,3,3];
- public Level(int depth, int recLimit, FieldType fieldType, Vector3 position){
- Debug.Log(position);
- switch(fieldType){
- case FieldType.Recursive:
- if(depth < recLimit){
- float sideLen = sideSize / (float)Math.Pow(3, depth);
- for(int x = 0; x < 3; x++){
- for(int y = 0; y < 3; y++){
- for(int z = 0; z < 3; z++){
- if(
- (x != 1 || z != 1 || y != 0) &&
- (x != 1 || z != 1 || y != 1) &&
- (x != 0 || z != 1 || y != 1) &&
- (x != 1 || z != 0 || y != 1) &&
- (x != 2 || z != 1 || y != 1) &&
- (x != 1 || z != 2 || y != 1) &&
- (x != 1 || z != 1 || y != 2)
- ) {
- lowerLevel[x, y, z] = new Level(
- depth+1,
- recLimit,
- FieldType.Recursive,
- position + new Vector3(x, y, z) * sideLen
- );
- }
- }
- }
- }
- break;
- }
- goto case FieldType.Cube;
- case FieldType.Cube:
- GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
- cube.transform.position = position;
- cube.transform.localScale = new Vector3(1, 1, 1) * sideSize / (float)Math.Pow(3, depth - 1);
- break;
- }
- }
- }
- public class SpawnCubes : MonoBehaviour
- {
- void Start()
- {
- Level l = new Level(0, 4, FieldType.Recursive, new Vector3(1, 1, 1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement